Need to understand code

F

Farrel Lifson

This is an extract from
http://www.codeforpeople.com/lib/ruby/arrayfields/arrayfields-3.5.0/README
that i am trying to understand.



relation = pgconn.query sql
relation.size #=> 65536

# yikes! do we really want to re-construct a hash for for each
tuple when
# we already have Arrays?

fields = %w(ssn name position)
table.each{|tuple| tuple.fields = fields}

tuples[34578]['ssn'] #=> 574865032

What does this term mean %w.......

%w(ssn name position) is the same as ["ssn", "name", position"]

Farrel
 
D

Daniel Schierbeck

What does this term mean %w.......

It's a shorthand used for creating arrays of strings:

%w{a b c d} #=> ["a", "b", "c", "d"]

Basically, the character that follows `%w' is the delimiter. So:

%w<delimiter> foo bar baz <delimiter> => ["foo", "bar", "baz"]

i.e.

%w& foo bar & #=> ["foo", "bar"]

If the starting delimiter is `(', `{', `[', or `<', then the matching
closing symbol will be the closing delimiter:

%w<foo bar baz> #=> ["foo", "bar", "baz"]

Read more on <http://www.rubycentral.com/book/language.html>


Cheers,
Daniel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

[ANN] arrayfields-3.6.0 0
[ANN] arrayfields-3.0.0 14
[ANN] arrayfields-3.4.0 3
[ANN] arrayfields-3.1.0 - the kirk haines release 2
[ANN] arrayfields-3.7.0 0
ANN main-4.4.0 0
[ANN] main-3.0.1 0
[ANN] sldb-0.1.0 0

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top