Posted By

wdso on 06/10/09


Tagged

ruby


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

wdso
webstic


Be careful with immediate values


 / Published in: Ruby
 

What a gotcha!

  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  

You need to login to post a comment.