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

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?

Returns:

  • (Boolean)


14
15
16
# File 'lib/emissary/core_ext/blank.rb', line 14

def blank?
  respond_to?(:empty?) ? empty? : !self
end

#clone_deepObject



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.

Returns:

  • (Boolean)


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