From: Chad Fowler Date: 2003-01-12T14:28:51+09:00 Subject: Re: Instance vars as arguments to initialize()? Jim Bob wrote: >In article , Jim Bob wrote: > > >> Wouldn't it be neater to be able to do "def initialize(@a, @b, >> @c);end" and be done with it? >> >> > >Well, to follow up to myself, I would have to say that wouldn't make a >whole lot of sense. initialize would have to be some kind of "special" >method to act like that, much more so than it is now. > >I've solved my "problem", such as it was, by writing a little Vim script >(using Ruby!) that, when called on a line like "A b c", builds a > class A > def initialize(b, c) > @b = b > @c = c > end > end >-type skeleton out of it. It was fun, too. > > > Another fun little Ruby-ism is that you could use "Struct" as a shortcut for constructing the initializer as in the following example: ====BEGIN==== Blah = Struct.new("Blah", :a, :b, :c) class Blah def extra_method puts "Here's some non-instance-var behaviour" end end x = Blah.new("Hello World",Math::PI,["an", "array", "of", "strings"]) x.extra_method #=> prints "Here's some non-instance-var behaviour" puts x.a #=> prints "Hello World" ====END==== Chad