From: Vincent Fourmond Date: 2006-09-20T20:30:49+09:00 Subject: Re: simple code doesnt work Hello Vince ;-) ! > Im getting this error > cf.rb:26: undefined method `price' for # @d="11/12/2006", @price=5.0, @v="yer"> (NoMethodError) > > thanks, just learning :-) > > > class Ticket > [...] > def price=(amount) > @price = amount > end > end > > ticket = Ticket.new("yer","11/12/2006") > puts "ticket stuff is #{ticket.venue} #{ticket.date}" > > ticket.price = (5.00) > > puts "ticket mooch is #{ticket.price}" You define the price= method, but you don't define the price method. You can't access to instance variables from outside the instance unless you explicitly allow it via appropriate accessors. In your case, replacing the price= definition by attr_accessor :price should work pretty well. You might want to use attr_reader to only grant read acces to an instance variable or attr_writer to only grant write access. Enjoy ! Vince (yet another one...)