On 1/18/07, ara.t.howard / noaa.gov <ara.t.howard / noaa.gov> wrote:
> On Fri, 19 Jan 2007, Pit Capitain wrote:
>
> > David Chelimsky schrieb:
> >> I find that I do a lot of this:
> >>
> >> def initialize(thing, other)
> >>  @thing = thing
> >>  @other = other
> >> end
> >>
> >> One thing I'd love to see in a future version of ruby is this;
> >>
> >> def initialize(@thing, @other)
> >> end
> >
> > Not that I would do it, but:
> >
> >  class C
> >    define_method :initialize do |@x, @y|
> >    end
> >  end
> >
> >  c = C.new 1, 2
> >  p c              # => #<C:0x2aeabd0 @y=2, @x=1>
> >
> > I think Matz is planning to deprecate this feature.
> >
> > Regards,
> > Pit
>
>    harp:~ > cat a.rb
>    require 'rubygems'
>    require 'attributes'
>
>    class C
>      attributes %w( a b c )
>
>      def initialize *argv
>        self.class.attributes.zip(argv){|a,v| send a, v}
>      end
>    end
>
>    p(C.new(0,1,2))
>
>    harp:~ > ruby a.rb
> #<C:0xb74c1b44 @c=2, @b=1, @a=0>
>

Thanks for all the responses, but I'm really looking for something
that feels simple and explicit (these suggestions all feel a little
magical and confusing).

Do any of you think this would be a good or bad thing to add to the
language? I'd like to post an RCR, but the RCRchive warns against
poorly researched requests - so I'd like to do some research ;) My
feeling is that my proposal would add a very simple and explicit means
of assigning those args that you wish to assign. What's yours?

Thanks,
David