Favorites

May 23rd, 2013

Sometimes, I wanna set more than one var at once. This is one of my very favorite ruby tricks that I use every day:


irb(main):007:0> a = [1, 2, 3]
=> [1, 2, 3]
irb(main):008:0> x, y, z = a.collect{|i| i * 2 }
=> [2, 4, 6]
irb(main):009:0> x
=> 2
irb(main):010:0> y
=> 4
irb(main):011:0> z
=> 6

Entry Filed under: Professional,Ruby on Rails

1 Comment Add your own

  • 1. steve  |  February 5th, 2014 at 12:35 pm

    Thank you for these code examples which are set out easily especially for a beginner like me. IKeep up the good work!

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Pages

Tweets

What does “making it” mean to you? When is what you have enough? The reality isn’t as glamorous, or as meaningful, or as fulfilling as it appears. twitter.com/aspleenic/stat…

About 3 weeks ago from Liana Leahy's Twitter via Twitter for iPhone

Meta