Thursday, May 17, 2012

[Rails] can someone explain how map! / connect! works in this case?

I just don't get it, how does it know which value to write out? If I
change the array number say to 10 instead of three and change the word
"three" to "ten" in the block it comes as nil... is there something
special about 1..3 that I am missing?

ary = [0,1,1,1,1,3]
ary.map! { |num| %w(zero one two three)[num] }

p ary
["zero", "one", "one", "one", "one", "three"]

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate