From: Matthew Desmarais Date: 2005-12-10T06:27:30+09:00 Subject: Re: different methods for initializing one object? >One way would be to take keyword arguments and figure out which you were >given. > >class Point2D > def initialize( params ) > if params.has_key? :r and params.has_key? :theta > ## initialize from polar > elsif params.has_key? :x and params.has_key? :y > ## initialize from cartesian > else > raise ArgumentError.new( "You must provide either :r and :theta OR >:x and :y" ) > end > end >end > >cart = Point2D.new( :x => 42, :y => -4 ) >polar = Point2D.new( :r => 3.14159, :theta => (Math::PI/4) ) > > Hi Mike, What you've proposed is a fine idea, but I think that it's important to be clear about your terminology. Ruby doesn't currently have keyword arguments. In the example that you've provided you are passing a hash with symbols for keys into the initialize method and _not_ using keywords. Regards, Matthew J Desmarais