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=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Pages

Tweets

@jcallina @lleahy :-( I'll send you links to the talks when they're available. Really great stuff tonight.

Last week from Liana Leahy's Twitter via Twitter for iPhone

Meta