> On Wed, May 22, 2002 at 08:59:42PM +0900, Henry Ghusakovsky wrote:
> > Hi everybody,
> >
> > Is there any possibility to create my own accessor like standard
accessors
> >
> Sure. Here is one that I did a while back:
>
> class Module
>   def attr_scale_reader(*attrs)
>     attrs.each { |attr|
>       class_eval %{
>         def #{attr}_d
>           @#{attr}/@scale
>         end
>       }
>     }
>   end#attr_scale_reader
> end
>
> This works a little different than the standard attr_reader,
> in that it creates a function name that is different than
> the attrs argument.
>
> For your hash_reader, you could write
>
> class Module
>   def hash_reader(*attrs)
>     attrs.each { |attr|
>       class_eval %{
>         def #{attr}
>           @data['#{attr}']
>         end
>       }
>     }
>   end#hash_reader
> end
> # warning, code is not tested
>
> I'm sure that you can create the writer and accessor
> functions from this example.
>
> Cheers
> Jim

thanks a lot


Best regards,

Henry Ghusakovsky
mail: H.Ghusakovsky(&)sam-solutions.net
ICQ# 34523185