In Ruby why won't `foo = true unless defined?(foo)` make the assignment?

后端 未结 7 932
悲哀的现实
悲哀的现实 2020-12-03 14:48

What\'s going on here? What is the subtle difference between the two forms of \"unless\"?

> irb(main):001:0> foo = true unless defined?(foo)
=> nil         


        
7条回答
  •  眼角桃花
    2020-12-03 15:09

    August, all look fine in 1.8.7:

    $ irb
    irb(main):001:0> unless defined?(fooo); fooo = true; end
    => true
    irb(main):002:0> fooo
    => true
    irb(main):003:0> `ruby --version`
    => "ruby 1.8.7 (2008-06-20 patchlevel 22) [i486-linux]\n"
    

提交回复
热议问题