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

Need fallback method for methods defined in state context (DRY) #278

Open
DougPuchalski opened this issue Aug 29, 2013 · 1 comment
Open

Comments

@DougPuchalski
Copy link

It feels like a method defined in a state context should override a method defined outside of it, i.e. a normal instance method of a class.

If I define the instance method, the same-named methods in the state context are never reached. If I do not define the instance method, then there is an exception if the method is called when in any state where it is not defined. Certainly not very DRY for a default case.

@DougPuchalski
Copy link
Author

Here's how I hacked my instance method definition to defer to context methods when available, required on a per-method/per-state basis unfortunately.

def message
  if (context_method = self.class.state_machines[:state].states[state].context_methods[__method__])
    context_method.bind(self).call
  else
    'default message'
  end
end

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

1 participant