Module: FirstOf

Included in:
Object
Defined in:
lib/first_of.rb,
lib/first_of/version.rb

Constant Summary collapse

VERSION =
"0.0.2"

Instance Method Summary collapse

Instance Method Details

#first_of(*args) ⇒ Object

Should take arguments: first_of(:symbol1, :symbol2) # will return first respond to and present first_of([:symbol1, :symbol2]) # will return value if try_chain(:symbol1, :symbol2) present first_of(1 => :symbol1, 2 => :symbol2) # will prioritize trying by key and return first present first_of(1 => :symbol1, 2 => lambda { _call }) # will prioritize and only execute callable if first not present first_of(1 => [:symbol1, :symbol2], 2 => -> { _call }) # will prioritize and execute try_chain on first and call 2nd if first not present first_of(1 => :symbol1, 2 => 4) # will prioritize and return value (4) if first not present first_of(lambda { _call }, 1 => :symbol1, 2 => :symbol2)



18
19
20
# File 'lib/first_of.rb', line 18

def first_of(*args)
  return _first_of(*args, :try_chain, :proxy_try_chain)
end

#first_of!(*args) ⇒ Object



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

def first_of!(*args)
  return _first_of(*args, :try_chain!, :proxy_try_chain!)
end