Module: PassNils

Defined in:
lib/pass_nils_to.rb

Instance Method Summary collapse

Instance Method Details

#pass_nils_to(method_sym, object = self) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/pass_nils_to.rb', line 2

def pass_nils_to(method_sym, object = self)
  method = object.method(method_sym.to_s)
  
  method.arity.times do |i|
    nils = Array.new(method.arity) { nil }
    nils[i] = "foo"
    method.call(*nils)
  end
  
  if method.arity > 2
    method.arity.times do |i|
      nils = Array.new(method.arity) { nil }
      (method.arity - 1).times { |j| nils[i-j] = "foo" }
      method.call(*nils)
    end
  end
  
  nils = Array.new(method.arity) { nil }
  method.call(*nils)   # Call with all nils
end