Module: Gemmy::Patches::MethodPatch::InstanceMethods::Bind
- Defined in:
- lib/gemmy/patches/method_patch.rb
Overview
Bind an argument to a method. Very useful for the proc shorthand. For example say there’s a method “def add(a,b); print a + b; end” You can run it for each number in a list:
[1,2,3].each &method(:add).bind(1)
=> 234
Instance Method Summary collapse
Instance Method Details
#bind(*args) ⇒ Object
18 19 20 21 22 |
# File 'lib/gemmy/patches/method_patch.rb', line 18 def bind *args Proc.new do |*more| self.call *(args + more) end end |