Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/emissary/core_ext/blank.rb,
lib/emissary/core_ext/misc_object.rb
Overview
BORROWED FROM ACTIVESUPPORT #####
Instance Method Summary collapse
- #__caller__ ⇒ Object
- #__method__ ⇒ Object
-
#blank? ⇒ Boolean
An object is blank if it’s false, empty, or a whitespace string.
- #clone_deep ⇒ Object
-
#present? ⇒ Boolean
An object is present if it’s not blank.
- #try(name, *args) ⇒ Object
Instance Method Details
#__caller__ ⇒ Object
13 14 15 16 |
# File 'lib/emissary/core_ext/misc_object.rb', line 13 def __caller__ caller[1] =~ /\d:in `([^']+)'/ $1.to_sym rescue nil end |
#__method__ ⇒ Object
8 9 10 11 |
# File 'lib/emissary/core_ext/misc_object.rb', line 8 def __method__ caller[0] =~ /\d:in `([^']+)'/ $1.to_sym rescue nil end |
#blank? ⇒ Boolean
An object is blank if it’s false, empty, or a whitespace string. For example, “”, “ ”, nil
, [], and {} are blank.
This simplifies
if !address.nil? && !address.empty?
to
if !address.blank?
14 15 16 |
# File 'lib/emissary/core_ext/blank.rb', line 14 def blank? respond_to?(:empty?) ? empty? : !self end |
#clone_deep ⇒ Object
18 19 20 |
# File 'lib/emissary/core_ext/misc_object.rb', line 18 def clone_deep Marshal.load(Marshal.dump(self)) rescue self.clone end |
#present? ⇒ Boolean
An object is present if it’s not blank.
19 20 21 |
# File 'lib/emissary/core_ext/blank.rb', line 19 def present? !blank? end |
#try(name, *args) ⇒ Object
4 5 6 |
# File 'lib/emissary/core_ext/misc_object.rb', line 4 def try name, *args self.__send__(name, *args) unless not self.respond_to? name end |