Created
June 27, 2013 07:27
-
-
Save arnab/5874594 to your computer and use it in GitHub Desktop.
Another weirdness between Ruby 1.8 and Ruby 1.9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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