Forum: Ruby Machinist with Plain Old Ruby Objects

Posted by Sean DeNigris (Guest)
on 2010-03-07 20:56
(Received via mailing list)
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
Posted by Brian Candler (candlerb)
on 2010-03-08 13: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 by Sean DeNigris (Guest)
on 2010-03-09 05:00
(Received via mailing list)
> 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
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.