On Monday, January 6, 2003, 7:48:18 PM, Tom wrote:

>>
>>   attr_accessor :x, :y, :name => :to_s, :age => :to_i
>>

> yea, that works well. unless there's some unforseen wrong doing here i'll 
> modify my code to work as you suggest. no need for another method at all! 
> very nice.

> hmm..just occured to me, how will the code handle it if there are only hash 
> arguments? in other words i'm not so sure what the methods args should be. 
> suggestion?

It will handle fine.  This (untested) is like a skeleton:

  def attr_accessor(*args)
    args.each do |arg|
      if arg.is_a Hash
        arg.each do |name, cast|
          # Create accessor methods with 'name' and 'cast'
        end
      else
        # Create normal accessor methods
      end
    end
  end

Naturally, you need attr_reader and attr_writer to work as intended,
so they are the building blocks for attr_accessor.

Muck around in irb or with some small programs to see for yourself
how optional hashes are processed, for example the following
invocation:

  foo 1, 2, 'a' => 5, 'b' => -7, :x => :y


Gavin