Module: ClientDataAdapter::Util

Defined in:
lib/client-data-adapter/util.rb

Class Method Summary collapse

Class Method Details

.merge(*elements) ⇒ Object

Merge some hash.

Parameters:

  • elements (Hash)


9
10
11
12
13
14
15
16
17
# File 'lib/client-data-adapter/util.rb', line 9

def merge(*elements)
  {}.tap do |hsh|
    elements.each do |elem|
      elem.each do |k, v|
        hsh[k] = v
      end
    end
  end
end

.to_lambda(source_proc) ⇒ Lambda

Convert a Proc to Lambda.

Parameters:

  • source_proc (Proc)

Returns:

  • (Lambda)


23
24
25
26
27
28
29
30
31
32
33
# File 'lib/client-data-adapter/util.rb', line 23

def to_lambda(source_proc)
  return source_proc if source_proc.lambda?

  unbound_method = Module.new.module_eval do
    instance_method(define_method(:_, &source_proc))
  end

  lambda do |*args, &block|
    unbound_method.bind(self).call(*args, &block)
  end
end