Module: Corefines::Symbol::Call

Defined in:
lib/corefines/symbol.rb

Instance Method Summary collapse

Instance Method Details

#call(*args, &block) ⇒ Proc

An useful extension for &:symbol which makes it possible to pass arguments for method in a block

Examples:

[1, 2, 3].map(&:to_s.(2)) #=> ['1', '10', '11']
%w[Chloe Drew Uma].map(&:gsub.('e', 'E')) #=> %w[ChloE DrEw Uma]

Parameters:

  • *args

    arguments being passed to the method.

  • block

    a block being passed to the method.

Returns:

  • (Proc)

    a proc that invokes the method, identified by this symbol and passing it the given arguments, on an object passed to it.


20
21
22
23
24
25
26
27
28
# File 'lib/corefines/symbol.rb', line 20

module Call
  refine ::Symbol do
    def call(*args, &block)
      proc do |recv|
        recv.__send__(self, *args, &block)
      end
    end
  end
end