Not an answer to the OP's question, but...

On Sun, Nov 23, 2008 at 5:27 PM, Michael Guterl <mguterl / gmail.com> wrote:
> On Sun, Nov 23, 2008 at 4:45 PM, Matthew Madson <merlin009_50 / yahoo.com> wrote:

> http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/241709

This implementation:

> def new_attr_reader cl, sym
>   str = "def #{sym.to_s}; @#{sym.to_s}; end"
>   cl.class_eval str
> end

is more dangerous than it needs to be.  Instead, you can write:

def new_attr_reader(*args)
  args.each { |e| define_method(e) { instance_variable_get("@#{e}") } }
end

Which allows for:

class A
  new_attr_reader :a, :b, :c

  def initialize
    @a = 1
    @b = 2
    @c = 3
  end
end

a = A.new
p [a.a, a.b, a.c] #=> [1, 2, 3]

Of course, substitute instance_variable_set for writers.

-- 
Technical Blaag at: http://blog.majesticseacreature.com | Non-tech
stuff at: http://metametta.blogspot.com