not sure I understand your question correctly, but Ruby does not offer
boolean data type as in many other programming languages. However,
there are “true” and “false” objects which you can use for that
v = true # or v = false
if v then
puts “v is true”
puts “v is false”
I have some trouble. How can i define the binary of value in ruby? (I
have a value, and I want to know that’s it true or false).
You don’t really need to. Everything in ruby has a “truthiness” to it
and can be used in logical expressions. Only nil and false are “falsey”
and everything else are “truthy”. In other words, just use objects and
they’ll take care of you.
if var then
If you feel REALLY insecure about typing in a dynamic language you can
if var.truthy? then # wasted cycles for no gain
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.