# Need to understand code

**URL:** <https://www.ruby-forum.com/t/need-to-understand-code/102381>\
**Category:** Ruby\
**Created:** [August 15, 2006, 2:16pm UTC](https://www.ruby-forum.com/t/need-to-understand-code/102381 "2006-08-15T14:16:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [August 15, 2006, 2:16pm UTC](https://www.ruby-forum.com/t/need-to-understand-code/102381/1 "2006-08-15T14:16:39Z")

</div>

This is an extract from  
[http://www.codeforpeople.com/lib/ruby/arrayfields/arrayfields-3.5.0/README](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…

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [August 15, 2006, 2:16pm UTC](https://www.ruby-forum.com/t/need-to-understand-code/102381/2 "2006-08-15T14:16:41Z")

</div>

On 8/11/06, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> fields = %w(ssn name position)
> 
> ```

> What does this term mean %w…

> ```
> fields = %w(ssn name position)
> 
> ```

is the same as [‘ssn’, ‘name’, ‘position’], i.e. %w is a syntactic  
shortcut.  
[http://www.rubycentral.com/book/language.html#UB](http://www.rubycentral.com/book/language.html#UB)

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [August 15, 2006, 2:16pm UTC](https://www.ruby-forum.com/t/need-to-understand-code/102381/3 "2006-08-15T14:16:41Z")

</div>

On 11/08/06, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> tuple when

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

Farrel

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [August 15, 2006, 2:16pm UTC](https://www.ruby-forum.com/t/need-to-understand-code/102381/4 "2006-08-15T14:16:42Z")

</div>

removed\_email\_address@domain.invalid wrote:

> 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 foo bar baz =\> [“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”]

Read more on [http://www.rubycentral.com/book/language.html](http://www.rubycentral.com/book/language.html)

Cheers,  
Daniel
