These gists are to support this blog post.
Created
November 19, 2009 22:26
-
-
Save dgrijalva/239094 to your computer and use it in GitHub Desktop.
Ruby 1.8 -> 1.9 Forwards Compatibility
This file contains 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
# Ruby 1.8 | |
p({:a => '123', :b => '234'}) | |
#=> {:b=>"234", :a=>"123"} | |
# Ruby 1.9 | |
p({:a => '123', :b => '234'}) | |
#=> {:a=>"123", :b=>"234"} |
This file contains 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
# Ruby 1.8 | |
p Object.superclass | |
#=> nil | |
# Ruby 1.9 | |
p Object.superclass | |
#=> BasicObject |
This file contains 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
# Ruby 1.8 | |
a = 0 | |
%w{all your base}.each{|a| puts a} | |
puts "a = #{a}" | |
#=> all | |
#=> your | |
#=> base | |
#=> a = base | |
# Ruby 1.9 | |
a = 0 | |
%w{all your base}.each{|a| puts a} | |
puts "a = #{a}" | |
#=> all | |
#=> your | |
#=> base | |
#=> a = 0 |
This file contains 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
# Ruby 1.8 | |
%w{a b c}.each do |w| | |
p w | |
a += 1 | |
retry unless a > 5 | |
end | |
#=> "a" | |
#=> "a" | |
#=> "a" | |
#=> "a" | |
#=> "a" | |
#=> "b" | |
#=> "c" | |
# Ruby 1.9 | |
%w{a b c}.each do |w| | |
p w | |
a += 1 | |
retry unless a > 5 # BOOM! | |
end |
This file contains 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
# Ruby 1.8 | |
if a > 0 then a = 0 #okay | |
if a > 0 : a = 0 #okay | |
# Ruby 1.9 | |
if a > 0 then a = 0 #okay | |
if a > 0 : a = 0 #not okay |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment