i having problem understanding execution in following code snippet.
x = 5 puts (0..10).include?(x) ? "yes" : "no" it giving desired output yes. when omitting parentheses of include? method :
x = 5 puts (0..10).include? x ? "yes" : "no" then output false. using ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]
that because in second case ruby takes result of whole x ? "yes" : "no" expresion argument.
puts (0..10).include? x ? "yes" : "no" is equivalent to:
puts (0..10).include?(x ? "yes" : "no") ruby allows omit brackets method calls, there cases, when it's impossible omit them write you've intended.
Comments
Post a Comment