Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Events can't share name with methods in the Kernel module #263

Open
smathieu opened this issue Jun 25, 2013 · 3 comments
Open

Events can't share name with methods in the Kernel module #263

smathieu opened this issue Jun 25, 2013 · 3 comments

Comments

@smathieu
Copy link

I have the following class that defines an event named 'abort'.

class Run < ActiveRecord::Base
  state_machine :initial => :queued do
    event :abort do
      transition any => :aborted
    end
  end
end

When I try to fire the event, I get the following error:

NoMethodError: private method `abort' called for #<Run:0x007f9480936c70>

This is likely because the abort method is defined in the Kernel module or ruby, and thus is available for any object.

I've made a fork of the repo and reproduced the failure in a unit test.

smathieu@af2c1ff

@the8472
Copy link

the8472 commented Jun 25, 2013

You can probably work around this buy using the low level methods.

YourClass.state_machines[:name_of_machine].events[:abort].transition_for(instance_of_your_class).perform(args)

@smathieu
Copy link
Author

Probably, but that's an horrible hack :)

@the8472
Copy link

the8472 commented Jun 25, 2013

That's not a hack, it's just not using the instance helper methods, which are an abstraction over the one mentioned.

Alternatively you can remove/undef the method from your class before initializing the state machine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants