Skip to content

Instantly share code, notes, and snippets.

@rafaelss
Forked from tinogomes/gist:1006296
Created June 3, 2011 13:13
Show Gist options
  • Save rafaelss/1006315 to your computer and use it in GitHub Desktop.
Save rafaelss/1006315 to your computer and use it in GitHub Desktop.
.boolean? method for ruby objects
module RubyExt
module Boolean
def bool?
[ true, false ].include?(self)
end
end
end
::Object.__send__ :include, RubyExt::Boolean
@tinogomes
Copy link

digamos recebo uma classe e não um objeto como parametro, e neste caso não "funfaria"

def something(klass)
puts klass.bool? ? "bool" : "not bool"
end

something TrueClass # => not bool
something FalseClass # => not bool

sacou?

@rafaelss
Copy link
Author

rafaelss commented Jun 3, 2011

ruby-1.9.2-p180 :012 > FalseClass.bool?
 => false 
ruby-1.9.2-p180 :013 > TrueClass.bool?
 => false 

é, não testei com essas duas :D

@tinogomes
Copy link

pois é

;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment