From: Farrel Lifson Date: 2006-11-30T02:02:57+09:00 Subject: Re: Wrong results using named arguments On 29/11/06, Jason Vogel wrote: > Source: > > [a.rb] > class A > > attr_accessor :id > attr_accessor :name > > def initialize(id = nil, name = nil) > @id = id > @name = name > end > end > > [test.rb] > require 'a' > > a1 = A.new(:name => "test") > a2 = A.new(:name => "test2") > > p a1 > p a2 > > Results: > #"test"}, @name=nil> > #"test2"}, @name=nil> > > I expected: > > # > # > > So what nuby mistake am I making? > > Thanks, > Jason > > > Ruby really doesn't have named arguments, rather it uses a hash to fake it. Your initialize method for A should probably be written def initialize(args) @id = args[:id] @name = args[:name] end Farrel