Module: Support::Tryable

Included in:
Delegator, Object
Defined in:
lib/paradocs/support.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#try(method_name = nil, *args, &b) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/paradocs/support.rb', line 5

def try(method_name = nil, *args, &b)
  if method_name.nil? && block_given?
    if b.arity == 0
      instance_eval(&b)
    else
      yield self
    end
  elsif respond_to?(method_name)
    public_send(method_name, *args, &b)
  end
end

#try!(method_name = nil, *args, &b) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/paradocs/support.rb', line 17

def try!(method_name = nil, *args, &b)
  if method_name.nil? && block_given?
    if b.arity == 0
      instance_eval(&b)
    else
      yield self
    end
  else
    public_send(method_name, *args, &b)
  end
end