I had same issue,
I had couple of ideas, of course one was using Hash.

I tried to accomplish it another way,

class Canvas

    attr_accessor :args

    def rect
    #   Draw canvus using
    #   args.width
    #   args.length
    #   args.fill-color
    end

    def args
        if @args.nil?
            @args = Arguments.new
        end
        return @args
    end
end

class Arguments < Canvas
    attr_accessor :width, :length, :fill-color, :border-color

    def initialize
        return self
    end
end

canvas = Canvas.new
canvas.args.width = 5
canvas.args.height = 10
..
..
..
canvas.args.fill-color = 'Red'
canvas.args.border-color = 'Black'

canvas.rect


Is it too complicated ? !!

Mohammad



On Tue, 2004-10-19 at 19:04, Tim Hunter wrote:
> Looking for coding style advice...
> 
> I'm trying to write a method that describes a rectangle. A rectangle is
> defined by the x,y coordinates of its upper-left corner and its width and
> height. These values are required. Optionally, the rectangle can have
> "styles," like the fill color and the stroke color. Also optionally, the
> rectangle can have rounded corners, if you specify how much rounding you
> want in the x and y directions. (The default is square corners.)
> 
> The method I started with is:
> 
> def rect(x, y, width, height, rx=0, ry=0, styles=nil)
>         # blah, blah, blah
> end
> 
> Where the styles argument (if present) is a Hash formed by the usual
> trailing key=>value pairs. All very standard Ruby.
> 
> I was thinking that you'd create a square-corner rectangle like this:
> 
> canvas.rect(10, 10, 20, 30, :fill=>'black', :stroke='red')
> 
> But of course that doesn't work, because the styles hash
> "{:fill=>'black', :stroke=>'red'}" gets assigned to rx, not to styles. 
> 
> Of course, within rect I could test the class of rx and/or ry and if it's a
> Hash, assign it to styles, but that seems kludgy and insufficiently
> Rubyish. I could divide rect into two methods, rect and rounded_rect, but
> that means that the user has to remember an extra method name. I could make
> rx and ry required arguments. Blech.
> 
> Thoughts?
-- 
Mohammad Khan <mkhan / lextranet.com>
Legal Computer Solutions, Inc.