From: Kalman Noel Date: 2006-11-30T02:29:18+09:00 Subject: Re: Wrong results using named arguments Jason Vogel: > class A > > attr_accessor :id > attr_accessor :name > > def initialize(id = nil, name = nil) > @id = id > @name = name > end > end > # [...] > require 'a' > > a1 = A.new(:name => "test") > a2 = A.new(:name => "test2") > > p a1 > p a2 > > Results: > #"test"}, @name=nil> > #"test2"}, @name=nil> Your initialize method takes two (optional) arguments, the first of which is id. In your calls to A.new, you're passing exactly one argument, which is why id gets set, and name does not. More precisely, A.new(:name => 'test') is the same as A.new({:name => 'test'}) so you're passing a Hash. To achieve what you may want, do def initialize(opt = {}) @id = opt[:id] @name = opt[:name] end Kalman