-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Fri, 12 Apr 2002 05:21, Ian Macdonald wrote:
> On Fri 12 Apr 2002 at 02:15:25 +0900, you wrote:
> > >>>>> "S" == Sean Middleditch <elanthis / awesomeplay.com> writes:
> >
> > S> In the context of Ian McDonald's question - you have a reference of an
> > S> instance variable, but you want the value from that reference.
> > S> attr_accessor doesn't help in that case (that I can think of), does
> > it?
> >
> >  Its example was [ruby-talk:38034]
> >
> >     def each
> >       self.instance_variables.each { |attr| yield(eval attr) }
> >     end
> >
> >  I don't know why it want to do this but when I want to make the instance
> >  variables "public" I define accessors methods.
>
> They _are_ public, but I wanted to define an each method that would
> iterate over them. Perhaps the best way to do this is to opt for an
> instance hash (instead of multiple scalars) and iterate over its keys.
>
> Ian

if they are public and have getter methods why not use Object#__send__?

def each
  instance_variables.each do |attr|
    value = __send__(attr.intern)
    yield(value)
  end
end

- -- 
Signed,
Holden Glova
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE8tewg+mF116Lw2cQRAsYZAJwOoB0S/w5FkEqSvWhy0Glr8zLTNQCgiSAw
kfy7mPAtJzht0g9WsuoQLdY=
=HQCT
-----END PGP SIGNATURE-----