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
purpose:
v = true # or v = false
if v then
puts "v is true"
else
puts "v is false"
end
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
do_something
end
If you feel REALLY insecure about typing in a dynamic language you can always double-negate:
class Object
def truthy?
!!self
end
end
if var.truthy? then # wasted cycles for no gain
do_something
end
···
On Dec 6, 2011, at 12:05 , Misha Ognev wrote:
hi2all
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).