Be careful with immediate values


/ Published in: Ruby
Save to your folder(s)

What a gotcha!


Copy this code and paste it in your HTML
  1. # immediate values
  2. # e.g. true, false and Integers
  3. a = true # => true
  4. b = true # => true
  5.  
  6. def a.foo
  7. "bar"
  8. end
  9.  
  10. a.foo # => "bar"
  11. b.foo # => "bar"
  12.  
  13. # referenced values
  14. c = "foo" # => "foo"
  15. d = "foo" # => "foo"
  16.  
  17. def c.meep
  18. "blubb"
  19. end
  20.  
  21. d.meep # => undefined method

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.