Question 2:
nil in ruby can put in condition statement
such as if(nil) it will assume that's false
ex.
if(nil)
else
puts "nil is false"
end
sure it show me the string
Becuase I'm curious,I want to test more
puts nil==nil #Yeah that's true
puts !nil #true
puts !nil==true #true
puts nil==false #FALSE !!!
What happen in the last statement? [or I miss something]
That is a very interesting way you are looking at things, I would not
necessarily think Ruby's behavior as bad.
For myself I think rubies semantics can be expressed as follows
class Object
def true?
true
end
end
class NilClass
def true?
false.true?
end
end
class FalseClass
def true?
self
end
end
p true.true?
p "".true?
p nil.true?
Now - in the classical terms of thinking you have invoked above, if an
object evaluates to true or false just replace it by #true?. (you can
imagine the interpreter doing that e.g.)
You see somehow comparing
nil == false does not make too much sense in that context, as an analogy you
have
puts "42 is true" if 42
puts "42**2 is true 2" if 1764
and yet
42 == 1764 => false
Cheers
Robert
···
On 9/20/06, Hussachai Puripunpinyo <siberhus@hotmail.com> wrote:
--
Posted via http://www.ruby-forum.com/\.
--
Deux choses sont infinies : l'univers et la bêtise humaine ; en ce qui
concerne l'univers, je n'en ai pas acquis la certitude absolue.
- Albert Einstein