On Fri 12 Apr 2002 at 05:02:47 +0900, you wrote:

> 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

Because I'm still learning the language and hadn't discovered it yet :-)

In the end, it was simpler to reimplement my long list of instance
variables as a single hash and iterate over its keys instead.

Ian
-- 
Ian Macdonald               | "Pascal is Pascal is Pascal is dog meat."  
ian / caliban.org             | -- M. Devine and P. Larson, Computer
                            | Science 340 
                            | 
                            |