Module: HashClass::AssignIf

Defined in:
lib/hash-class/assign_if.rb

Instance Method Summary collapse

Instance Method Details

#assign_if(*opts, &block) ⇒ Object

lookup element and return value if exists



5
6
7
8
9
10
11
12
# File 'lib/hash-class/assign_if.rb', line 5

def assign_if(*opts, &block)
  if opts.is_a?(Array)
    el = opts.first
    if block.is_a?(Proc)
      return block.call(self[el]) if self.include?(el)
    end
  end
end