Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Extract state query method definition and quiet method redefinition w…

…arning.
  • Loading branch information...
commit 0e2d18e415118afed2df148e5d7302ef0361b569 1 parent 0492759
@jeremy jeremy authored
View
6 activemodel/lib/active_model/state_machine.rb
@@ -31,6 +31,12 @@ def state_machine(name = nil, options = {}, &block)
state_machines[name] ||= Machine.new(self, name)
block ? state_machines[name].update(options, &block) : state_machines[name]
end
+
+ def define_state_query_method(state_name)
+ name = "#{state_name}?"
+ undef_method(name) if method_defined?(name)
+ class_eval "def #{name}; current_state.to_s == %(#{state_name}) end"
+ end
end
def current_state(name = nil, new_state = nil, persist = false)
View
7 activemodel/lib/active_model/state_machine/state.rb
@@ -5,11 +5,8 @@ class State
def initialize(name, options = {})
@name = name
- machine = options.delete(:machine)
- if machine
- machine.klass.send(:define_method, "#{name}?") do
- current_state.to_s == name.to_s
- end
+ if machine = options.delete(:machine)
+ machine.klass.define_state_query_method(name)
end
update(options)
end
Please sign in to comment.
Something went wrong with that request. Please try again.