Class: Object

Inherits:
BasicObject
Defined in:
lib/swee/support.rb

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/swee/support.rb', line 19

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

#presenceObject



26
27
28
# File 'lib/swee/support.rb', line 26

def presence
  self if present?
end

#present?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/swee/support.rb', line 22

def present?
  !blank?
end

#try(*a, &b) ⇒ Object



3
4
5
# File 'lib/swee/support.rb', line 3

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

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



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/swee/support.rb', line 7

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