Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Support nil means pass nothing and passing blocks.

  • Loading branch information...
commit 4686e1edf529c1262e26b7f2f7da720036124aac 1 parent b6b6604
Stephen Paul Weber authored

Showing 1 changed file with 19 additions and 5 deletions. Show diff stats Hide diff stats

  1. +19 5 rpnr-runtime.rb
24 rpnr-runtime.rb
@@ -48,15 +48,29 @@ def puts
48 48 Kernel::puts(to_s)
49 49 end
50 50
51   - # Handle multiple-airity methods being passed a list magically
  51 + # Handle multiple-airity methods being passed a list/block magically
52 52 def magic_send(message, arg)
53 53 arity = method(message).arity
54 54 if arity == 0
55   - send(message)
56   - elsif arg.is_a?(Array) && arity != 1
57   - send(message, *arg)
58   - else
  55 + send(message, &arg)
  56 + elsif arity == 1
59 57 send(message, arg)
  58 + else
  59 + case arg
  60 + when nil
  61 + send(message)
  62 + when Array
  63 + if arg.length > arity.abs && arg.last.is_a?(Proc)
  64 + blk = arg.pop
  65 + send(message, *arg, &blk)
  66 + else
  67 + send(message, *arg)
  68 + end
  69 + when Proc
  70 + send(message, &arg)
  71 + else
  72 + send(message, arg)
  73 + end
60 74 end
61 75 end
62 76 end

0 comments on commit 4686e1e

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