3. Quoting Strings Double quotes interpolate >> me = "double quotes are awesome” >> "I am a string withdouble quotes. #{me}" => "I am a string with double quotes. double quotes are awesome" Single quotes don’t interpolate >> 'I am a string withsingle quotes. #{me}' => "I am a string withssingle quotes.n {me}"
7. More String Formatting >> full_name.downcase! => "yukihiro matsumoto" >> full_name.capitalize => "Yukihiro matsumoto" Making our own title case method: >> full_name.split.map {|w| w.capitalize}.join(" ") => "Yukihiro Matsumoto" We can also get title case using regex
14. each_char: process charactercareful of 1.8.x and 1.9 differences>> word = "こにちわ" => "こにちわ" >> word.each_byte do |s| puts s end 227 129 >> word = "こにちわ" => "こにちわ" >> word.each_char do |s| puts s end こ に ち わ
15. Iterate Using Split returns an array of partial strings exploded at a separator secret_code = "the black dove flies at night” secret_code.split(" ").each do |s| puts s.reverse end eht kcalb evod seilf ta thgin
17. What is a Symbol? A symbol represents a name. Instances of the built-in class Symbol. They efficiently describe names while saving the space one would use to generate a string for each naming instance.
18. A Symbol is not a String :thing != “thing” However a symbol can be create from a string: “thing”.to_sym And a string can be created from a symbol :thing.to_s
19. Symbols are Immutable You can’t change a symbol For example, you can’t append characters to a symbol...once a symbol exists, that’s it! >> :name + :me NoMethodError: undefined method `+' for :name:Symbol from (irb):182 from :0 >> :name << :me NoMethodError: undefined method `<<' for :name:Symbol from (irb):183 from :0
20. Symbols are Unique :name is the only symbol object called :name >> :name.object_id => 68828 >> :name.object_id => 68828 “name” is a new String object each time it is instantiated >> "name".object_id => 2157595700 >> "name".object_id => 2157591380