Skip to content

Instantly share code, notes, and snippets.

@arnab
Created June 27, 2013 07:27
Show Gist options
  • Save arnab/5874594 to your computer and use it in GitHub Desktop.
Save arnab/5874594 to your computer and use it in GitHub Desktop.
Another weirdness between Ruby 1.8 and Ruby 1.9
stuff = (1..10).to_a
# => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
stuff = stuff.detect { |stuff| stuff.even? } ? stuff : 'none found'
#### Ruby 1.8 #######
# => 2
# So, #detect first runs, finds 2 and the result is reassigned into "stuff"
# the ternary operation follows, with "stuff" set to 2
#### Ruby 1.9 #######
# => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# So, the ternary operator is invoked before the result of #detect is reassigned into "stuff"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment