Created
February 28, 2010 18:18
-
-
Save schmurfy/317710 to your computer and use it in GitHub Desktop.
Ruby 1.9 changes Quick Reference
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
# some nice ruby 1.9 additions | |
str = arr.map(&:firstname) # if arr is an array of user object (worked in ruby 1.8 with activesupport but now native in ruby 1.9) | |
# map, each, etc... returns an iterator object with a with_index method | |
arr.map.with_index {|element, i| ... } | |
arr.each.with_index {|element, i| ... } | |
# lambda can have default parameters | |
p = proc{|a, b = 3| ... } | |
# each string has an internal encoding now (utf8 is default ?) | |
str = "something" | |
str.encoding => #<Encoding:UTF-8> | |
str.encode('ascii') => "something" | |
str = "téléphone" | |
str.encode('ascii') => Encoding::UndefinedConversionError: "\xC3\xA9" from UTF-8 to US-ASCII | |
str.encode("ascii", :invalid => :replace, :undef => :replace) => "t?l?phone" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment