From: Sean DeNigris on 7 Mar 2010 14:56 Does anyone have experience with this? Specifically, I want to use a blueprint for a class that takes an argument to new, but calling make (even with an argument) causes an error. Example: class MyClass def initialize(str) ... end end MyClass.make #or MyClass.make('a string') #or MyClass.make('new' => 'a string') Output: wrong number of arguments (0 for 1) Thanks. Sean
From: Brian Candler on 8 Mar 2010 07:29 Sean DeNigris wrote: > Specifically, I want to use a blueprint for a class that takes an > argument to new, but calling make (even with an argument) causes an > error. > > Example: > class MyClass > def initialize(str) > ... > end > end > > MyClass.make > #or > MyClass.make('a string') > #or > MyClass.make('new' => 'a string') > > Output: > wrong number of arguments (0 for 1) Can you show the source for your 'make' class method? The following works for me: class MyClass def self.make(*args) new(*args) end def initialize(str) @str = str end end MyClass.make("hello") -- Posted via http://www.ruby-forum.com/.
From: Sean DeNigris on 8 Mar 2010 23:00 > Can you show the source for your 'make' class method? Make is a method added to Object by the gem. It did not support objects that take arguments to new. I added the functionality at http://github.com/lotusone/machinist. Thanks! Sean DeNigris
|
Pages: 1 Prev: [ANN] mongrel_service 0.4.beta3 Released Next: win32console 1.3.0.beta2 Released |