Class: Object

Inherits:
BasicObject
Defined in:
lib/ruby_smart/support/core_ext/ruby/object.rb,
lib/ruby_smart/support/core_ext/ruby/object.rb,
lib/ruby_smart/support/core_ext/ruby/object.rb,
lib/ruby_smart/support/core_ext/ruby/object.rb

Instance Method Summary collapse

Instance Method Details

#alias_missing_method(new, old, check_ancestors = true) ⇒ Object

creates an alias for provided method if it's missing. the third optional parameter check_ancestors prevents to check it's ancestors by providing a false value

Parameters:

  • new (Symbol)
    • new method name
  • old (Symbol)
    • old method name
  • check_ancestors (Boolean) (defaults to: true)
    • check class ancestors (default: true)


47
48
49
# File 'lib/ruby_smart/support/core_ext/ruby/object.rb', line 47

def alias_missing_method(new, old, check_ancestors = true)
  alias_method(new, old) if missing_method?(new, check_ancestors)
end

#boolean?Boolean

return true if object is a boolean class (TrueClass or FalseClass)

Returns:

  • (Boolean)

    boolean



21
22
23
# File 'lib/ruby_smart/support/core_ext/ruby/object.rb', line 21

def boolean?
  self.is_a?(TrueClass) || self.is_a?(FalseClass)
end

#missing_method?(name, check_ancestors = true) ⇒ Boolean

returns true if method is missing. the second optional parameter check_ancestors prevents to check it's ancestors by providing a false value

Parameters:

  • name (Symbol)
    • the method's name to check
  • check_ancestors (Boolean) (defaults to: true)
    • check class ancestors (default: true)

Returns:

  • (Boolean)

    missing_method



34
35
36
# File 'lib/ruby_smart/support/core_ext/ruby/object.rb', line 34

def missing_method?(name, check_ancestors = true)
  !self.instance_methods(check_ancestors).include?(name)
end

#numeric?Boolean

returns true if this object is a numeric or a kind of numeric

Returns:

  • (Boolean)

    numeric



7
8
9
10
11
12
13
# File 'lib/ruby_smart/support/core_ext/ruby/object.rb', line 7

def numeric?
  return true if self.is_a?(Numeric)
  return true if self.to_s =~ /\A\d+\Z/
  return true if Float(self) rescue false

  false
end