From: Florian Frank Date: 2004-10-07T00:10:17+09:00 Subject: Re: quality of error messages On 06.10.2004, at 15:48, Joachim Wuttke wrote: > Example 2: NoMethodError: undefined method. > -> Wrong, I defined the method. I just forgot to > include it in the attr_reader list. The system > shouldn't mislead me. It doesn't. If you define the method with "def" yourself, you don't have to call attr_reader at all. attr_reader :foobar generates an instance method like def foobar @foobar end that returns the instance variable @foobar. You can actually define your own metaprogramming methods: class Module def attr_writer_positive(*ids) ids.each do |id| define_method("#{id}=") do |value| raise "not positive" unless value > 0 instance_variable_set("@#{id}", value) end end nil end end # => nil class Klass attr_writer_positive :foo end # => nil k = Klass.new # => # k.foo = 5 # => 5 k.foo = -5 RuntimeError: not positive from foo.rb:5:in `foo=' from foo.rb:4:in `foo=' from foo.rb:21 Florian Frank