Guest User

Untitled

a guest
Nov 20th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. 1. 如果 hash 需要初值的話,可以使用 `Hash.new(default_value)`
  2. ```ruby
  3. usually_brown = Hash.new("brown")
  4. pretending_to_be_there = usually_brown[:zig]
  5. puts "Pretending to be there:"
  6. p pretending_to_be_there
  7.  
  8. # => Pretending to be there:
  9. # => "brown"
  10. ```
  11.  
  12. 2. `1.next == 2`
  13. 3. method 也是一個物件
  14. ```ruby
  15. 'aaa'.method('upcase') # => String#upcase()
  16. 'aaa'.method('upcase').call # => "AAA"
  17. 'aaa'.upcase # => "AAA"
  18. ```
  19. 4. deep_symbolize_keys
  20. ```ruby
  21. hash = { 'person' => { 'name' => 'Rob', 'age' => '28' } }
  22.  
  23. hash.deep_symbolize_keys
  24. # => { person: { name: "Rob", age: "28" } }
  25. ```
Add Comment
Please, Sign In to add comment