ruby statement modifier local variables

irb(main):001:0> puts foo if foo = "foo"
(irb):1: warning: found = in conditional, should be ==
NameError: undefined local variable or method `foo' for main:Object
from (irb):1

irb(main):002:0> puts foo if(foo = "foo")
(irb):2: warning: found = in conditional, should be ==
foo
=> nil
irb(main):003:0>


Leave a Reply

Formatting: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>