Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/open_classes/object.rb
Overview
Object
Instance Method Summary collapse
-
#any_of?(*args) ⇒ Boolean
If self match any one of args, return true.
-
#boolean? ⇒ Boolean
Check boolean type.
-
#my_methods ⇒ Object
Get self define methods.
-
#to_bool ⇒ Object
you get bool value.
Instance Method Details
#any_of?(*args) ⇒ Boolean
If self match any one of args, return true.
"hoge".any_of? %w{hoge hige} # => true
"hige".any_of? %w{hoge hige} # => true
"hege".any_of? %w{hoge hige} # => false
47 48 49 50 |
# File 'lib/open_classes/object.rb', line 47 def any_of?(*args) args.each { |value|return true if self == value } false end |
#boolean? ⇒ Boolean
Check boolean type
boolean? true # => true
boolean? false # => true
boolean? nil # => false
boolean? 'true' # => false
boolean? 'false' # => false
boolean? '' # => false
13 14 15 |
# File 'lib/open_classes/object.rb', line 13 def boolean? self.is_a?(TrueClass) || self.is_a?(FalseClass) end |
#my_methods ⇒ Object
Get self define methods.
class SampleClass < String
def public_hello
"public hello"
end
protected
def protected_hello
"protected hello"
end
private
def private_hello
"private hello"
end
end
SampleClass.new.my_methods # => [:public_hello, :protected_hello, :private_hello]
38 39 40 |
# File 'lib/open_classes/object.rb', line 38 def my_methods public_methods(false) + protected_methods(false) + private_methods(false) end |
#to_bool ⇒ Object
you get bool value
true.to_bool # => true
false.to_bool # => false
0.to_bool # => true
1.to_bool # => true
''.to_bool # => true
'true'.to_bool # => true
'false'.to_bool # => true
nil.to_bool # => false
62 63 64 |
# File 'lib/open_classes/object.rb', line 62 def to_bool !!self end |