Skip to content

Instantly share code, notes, and snippets.

@ferrous26
Created December 27, 2012 01:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ferrous26/4384796 to your computer and use it in GitHub Desktop.
Save ferrous26/4384796 to your computer and use it in GitHub Desktop.
Varargs in MacRuby and MRI
def foo *args
arg = args.last
if arg.zero?
args
else
foo(args << arg - 1)
end
end
p foo 3
± macruby bug.rb
[3, 2, 1, 0]
± ruby bug.rb
bug.rb:3:in `foo': undefined method `zero?' for [3, 2]:Array (NoMethodError)
from bug.rb:6:in `foo'
from bug.rb:10:in `<main>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment