Skip to content

Instantly share code, notes, and snippets.

@dchelimsky
Created October 14, 2010 16:22
Show Gist options
  • Save dchelimsky/626494 to your computer and use it in GitHub Desktop.
Save dchelimsky/626494 to your computer and use it in GitHub Desktop.
ruby-1.9.2-p0 > class Foo; end
#=> nil
ruby-1.9.2-p0 > Foo.new('bar')
#=> #<Foo:0x00000100974e50>
ruby-1.9.2-p0 > class Foo; end
=> nil
ruby-1.9.2-p0 > Foo.new(1,2)
=> #<Foo:0x000001009dd4a0>
ruby-1.9.2-p0 > Foo.new(1,2,3, :a => 'b')
=> #<Foo:0x0000010181b918>
ruby-1.9.2-p0 > class Foo; def initialize; end; end
=> nil
ruby-1.9.2-p0 > Foo.new(1,2,3, :a => 'b')
ArgumentError: wrong number of arguments (4 for 0)
from (irb):5:in `initialize'
from (irb):6:in `new'
from (irb):6
from /Users/david/.rvm/rubies/ruby-1.9.2-p0/bin/irb:17:in `<main>'
@dchelimsky
Copy link
Author

The problem, btw, is that the earlier examples allow you to pass in args that are unexpected - not that the last example raises an error (that's what should happen in the earlier examples, in my view).

@rossmeissl
Copy link

So what do you think should be the arity on Object#new?

@dchelimsky
Copy link
Author

0, as it is in ruby-1.8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment