Constant Assigment Bug in Ruby?

Posted by aronchick on Stack Overflow See other posts from Stack Overflow or by aronchick
Published on 2010-06-09T23:47:32Z Indexed on 2010/06/09 23:52 UTC
Read the original article Hit count: 165

Filed under:

We caught some code in Ruby that seems odd, and I was wondering if someone could explain it:

$ irb
irb(main):001:0> APPLE = 'aaa'
=> "aaa"
irb(main):002:0> banana = APPLE
=> "aaa"
irb(main):003:0> banana << 'bbb'
=> "aaabbb"
irb(main):004:0> banana
=> "aaabbb"
irb(main):005:0> APPLE
=> "aaabbb"

Catch that? The constant was appended to at the same time the local variable was.

Known behavior? Expected?

© Stack Overflow or respective owner

Related posts about ruby