The test
def true?(x) if x return "true" else return "false" end end tests = [false,true,0,1,nil,[],{},"","0","1","true","false"] tests.each do |test| puts test.inspect+":\t "+true?(test)+" ("+test.class.to_s+")" end
The results
false: false (FalseClass) true: true (TrueClass) 0: true (Fixnum) 1: true (Fixnum) nil: false (NilClass) []: true (Array) {}: true (Hash) "": true (String) "0": true (String) "1": true (String) "true": true (String) "false": true (String)
For later reference.
No comments:
Post a Comment