Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. 如果 hash 需要初值的話,可以使用 `Hash.new(default_value)`
- ```ruby
- usually_brown = Hash.new("brown")
- pretending_to_be_there = usually_brown[:zig]
- puts "Pretending to be there:"
- p pretending_to_be_there
- # => Pretending to be there:
- # => "brown"
- ```
- 2. `1.next == 2`
- 3. method 也是一個物件
- ```ruby
- 'aaa'.method('upcase') # => String#upcase()
- 'aaa'.method('upcase').call # => "AAA"
- 'aaa'.upcase # => "AAA"
- ```
- 4. deep_symbolize_keys
- ```ruby
- hash = { 'person' => { 'name' => 'Rob', 'age' => '28' } }
- hash.deep_symbolize_keys
- # => { person: { name: "Rob", age: "28" } }
- ```
Add Comment
Please, Sign In to add comment