From: Tim Becker Date: 2007-03-04T03:14:48+09:00 Subject: Re: attr_reader explained On 3/3/07, libsfan01 wrote: > can someone explain how attr_reader works? > > i can't find a good explanation anywhere. > > please help! It's built in to the language, so it 'works' by magic for all practical purposes, it's implemented in `object.c` if you want to take a look at the implementation. If you wanted to implement it in Ruby, you do something like this: > def new_attr_reader cl, sym > str = "def #{sym.to_s}; @#{sym.to_s}; end" > cl.class_eval str > end >class Test; end >new_attr_reader Test, :my_new_reader >Test.new().my_new_reader The built in `attr_reader` takes an array of sym's, but you get the idea. -tim