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

后端 未结 7 923
悲哀的现实
悲哀的现实 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

    Well.. One form is a block and one form isn't. The second part, the block, returns the last statement evaluated. The first one.. Hrm.. I don't know exactly what it's doing.

    0 讨论(0)
提交回复
热议问题