i'm newbie in Ruby. Today i was coding some home exercise and founding this behavior of my code: if i try to execute the same code in irb and VSC in second case i don't get a single string of output.
Here's example from VSC:
def even_or_odd(number)
number.even? ? "Even" : "Odd"
end
even_or_odd(number)
This code don't give me an output in VSC, but if i try to execute this code in irb it works fine:
irb(main):001:1* def even_or_odd(number)
irb(main):002:1* number.even? ? "Even" : "Odd"
irb(main):003:0> end
=> :even_or_odd
irb(main):004:0> even_or_odd(32)
=> "Even"
irb(main):005:0>
What's the point?
you need to have puts on your vsc
change the var
numberto actual integer.but when in you run
irb, it automatically show return value to console, that's why it does not need puts.you can change this behavior by call
irb --noecho, then you will needputs