Class: Object

Inherits:
BasicObject
Defined in:
lib/active_object/object.rb

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


4
5
6
7
8
# File 'lib/active_object/object.rb', line 4

def blank?
  object = self
  object = object.strip if respond_to?(:strip)
  respond_to?(:empty?) ? !!object.empty? : !object
end

#numeric?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/active_object/object.rb', line 11

def numeric?
  !to_s.match(/\A[+-]?\d+?(\.\d+)?\Z/).nil?
end

#palindrome?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/active_object/object.rb', line 15

def palindrome?
  to_s == to_s.reverse
end

#present?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/active_object/object.rb', line 20

def present?
  !blank?
end

#try(*a, &b) ⇒ Object



26
27
28
# File 'lib/active_object/object.rb', line 26

def try(*a, &b)
  try!(*a, &b) if a.empty? || respond_to?(a.first)
end

#try!(*a, &b) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/active_object/object.rb', line 32

def try!(*a, &b)
  if a.empty? && block_given?
    b.arity.zero? ? instance_eval(&b) : yield(self)
  else
    public_send(*a, &b)
  end
end