Created
June 3, 2011 13:03
-
-
Save tinogomes/1006296 to your computer and use it in GitHub Desktop.
.boolean? method for ruby objects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module RubyExt | |
module Boolean | |
module ClassMethods | |
def boolean? | |
["TrueClass", "FalseClass"].include?(self.name) | |
end | |
end | |
module InstanceMethods | |
def boolean? | |
self.class.boolean? | |
end | |
end | |
def self.included(receiver) | |
receiver.extend ClassMethods | |
receiver.send :include, InstanceMethods | |
end | |
end | |
end | |
::Object.__send__ :include, RubyExt::Boolean |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Já precisei (e implementei) de algo parecido: de ter um método to_bool que existisse desde a classe Object.