ArgumentError with ruby-1.9.3

Skip to first unread message

Gurpartap Singh

Nov 22, 2012, 6:36:23 AM11/22/12

Things worked fine until I revisited my code a couple of months later using ruby-1.9.3 instead of the previous ruby-1.9.2. The class using state_machine can now not be initialized. This is the error I'm trying to troubleshoot.

/path/.bundle/ruby/1.9.1/gems/state_machine-1.1.2/lib/state_machine/machine.rb:1965:in `initialize': wrong number of arguments(2 for 0) (ArgumentError)
from /path/.bundle/ruby/1.9.1/gems/state_machine-1.1.2/lib/state_machine/machine.rb:1965:in `block in initialize'
from /path/.bundle/ruby/1.9.1/gems/state_machine-1.1.2/lib/state_machine/machine_collection.rb:34:in `initialize_states'
from /path/.bundle/ruby/1.9.1/gems/state_machine-1.1.2/lib/state_machine/machine.rb:1965:in `initialize' 
I have tried understanding the code attributed in backtrace. If `super` is omitted from machine.rb:1965's block, things seem to work (would probably break something elsewhere). So I'm looking for an informed opinion on whether this is a bug with state_machine, or if I am implementing something incorrectly (remember, it works fine on 1.9.2).

I'm using ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0]. As tested, there was no such error with ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.2.0].

Thank you.

Gurpartap Singh

Gurpartap Singh

Nov 23, 2012, 4:21:35 AM11/23/12
The project where state_machine is implemented, and the problem can be reproduced is here: Install (from source) and run `sudo cognizantd --trace /path/to/gems/cognizant/examples/cognizantd.yml` to reproduce the error.

I have posted this as an issue to the project issue queue on Github:

Gurpartap Singh

Dec 25, 2012, 7:25:01 AM12/25/12
As I read from `StateMachine::MacroMethods` documentation:

> Because of the way the inclusion of modules works in Ruby, calling super() will not only call the superclass's initialize, but also initialize on all included modules. This allows the original state machine hook to get called properly.

Using `initialize_state_machines` instead of `super` in my model's initialize method solved the problem (since my model also had included modules).


On Thursday, November 22, 2012 5:06:23 PM UTC+5:30, Gurpartap Singh wrote:
Reply all
Reply to author
0 new messages