Skip to content

Instantly share code, notes, and snippets.

@tinogomes
Created June 3, 2011 13:03
Show Gist options
  • Save tinogomes/1006296 to your computer and use it in GitHub Desktop.
Save tinogomes/1006296 to your computer and use it in GitHub Desktop.
.boolean? method for ruby objects
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
@leandro
Copy link

leandro commented Jun 3, 2011

Já precisei (e implementei) de algo parecido: de ter um método to_bool que existisse desde a classe Object.

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