def thing(input) item = input == "hi" if item [] end end puts thing("hi").class #> Array puts thing("not hi").class #> NilClass
我喜欢这个功能(如果语句为false则返回nil),但为什么不返回false(从赋值到项目)?
irb(main):001:0> i = if false then end => nil irb(main):002:0> i = if true then end => nil irb(main):007:0> i = if false then "a" end => nil irb(main):008:0> i = if false then "a" else "b" end => "b"