Skip to content
Browse files

Support nil means pass nothing and passing blocks.

  • Loading branch information...
1 parent b6b6604 commit 4686e1edf529c1262e26b7f2f7da720036124aac @singpolyma committed Mar 18, 2010
Showing with 19 additions and 5 deletions.
  1. +19 −5 rpnr-runtime.rb
View
24 rpnr-runtime.rb
@@ -48,15 +48,29 @@ def puts
Kernel::puts(to_s)
end
- # Handle multiple-airity methods being passed a list magically
+ # Handle multiple-airity methods being passed a list/block magically
def magic_send(message, arg)
arity = method(message).arity
if arity == 0
- send(message)
- elsif arg.is_a?(Array) && arity != 1
- send(message, *arg)
- else
+ send(message, &arg)
+ elsif arity == 1
send(message, arg)
+ else
+ case arg
+ when nil
+ send(message)
+ when Array
+ if arg.length > arity.abs && arg.last.is_a?(Proc)
+ blk = arg.pop
+ send(message, *arg, &blk)
+ else
+ send(message, *arg)
+ end
+ when Proc
+ send(message, &arg)
+ else
+ send(message, arg)
+ end
end
end
end

0 comments on commit 4686e1e

Please sign in to comment.
Something went wrong with that request. Please try again.