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]

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