tags:

views:

161

answers:

1

There has been quite a bit of talk lately on stackoverflow about bad ruby code and practices. I think it is about time we showcase some of the better aspects of Ruby. Instead of showing people all the horrible things Ruby can do lets show people some of the great clarifiers and time-savers of Ruby.

One of my personal favorites is multiple value assignment:

point = [ 1 , 2 ]
x,y = point

p x #=> 1
p y #=> 2, hooray!

or

x = 2
y = 1
x,y = y,x

p x #=> 1
p y #=> 2, hooray!

While multiple assignment can be abused (i.e. def initialize*d;@d,=d;end from this post to assign the first element of an array) it has a lot of good uses that are both logical and straight-forward.

What other idioms and practices do you use that greatly clarify/simplify your Ruby code?

A: 

See This Question

AShelly