def define_helper(scope, method, *args, &block)
      helper_module = @helper_modules.fetch(scope)

      if block_given?
        if !self.class.ignore_method_conflicts && conflicting_ancestor = owner_class_ancestor_has_method?(scope, method)
          ancestor_name = conflicting_ancestor.name && !conflicting_ancestor.name.empty? ? conflicting_ancestor.name : conflicting_ancestor.to_s
          warn "#{scope == :class ? 'Class' : 'Instance'} method \"#{method}\" is already defined in #{ancestor_name}, use generic helper instead or set StateMachines::Machine.ignore_method_conflicts = true."
        else
          name = self.name
          helper_module.class_eval do
            define_method(method) do |*block_args|
              block.call((scope == :instance ? self.class : self).state_machine(name), self, *block_args)
            end
          end
        end
      else
        helper_module.class_eval(method, *args)
      end
    end
def define_helper(scope, method, *args, &block)
      helper_module = @helper_modules.fetch(scope)

      if block_given?
        if !self.class.ignore_method_conflicts && conflicting_ancestor = owner_class_ancestor_has_method?(scope, method)
          ancestor_name = conflicting_ancestor.name && !conflicting_ancestor.name.empty? ? conflicting_ancestor.name : conflicting_ancestor.to_s
          warn "#{scope == :class ? 'Class' : 'Instance'} method \"#{method}\" is already defined in #{ancestor_name}, use generic helper instead or set StateMachines::Machine.ignore_method_conflicts = true."
        else
          name = self.name
          helper_module.class_eval do
            define_method(method) do |*block_args|
              block.call((scope == :instance ? self.class : self).state_machine(name), self, *block_args)
            end
          end
        end
      else
        helper_module.class_eval(method, *args)
      end
    end
Defines a new helper method in an instance or class scope with the given
 name.  If the method is already defined in the scope, then this will not
 override it.

 If passing in a block, there are two side effects to be aware of
 1. The method cannot be chained, meaning that the block cannot call +super+
 2. If the method is already defined in an ancestor, then it will not get
    overridden and a warning will be output.

 Example:

   # Instance helper
   machine.define_helper(:instance, :state_name) do |machine, object|
     machine.states.match(object).name
   end

   # Class helper
   machine.define_helper(:class, :state_machine_name) do |machine, klass|
     "State"
   end

 You can also define helpers using string evaluation like so:

   # Instance helper
   machine.define_helper :instance, <<-end_eval, __FILE__, __LINE__ + 1
     def state_name
       self.class.state_machine(:state).states.match(self).name
     end
   end_eval

   # Class helper
   machine.define_helper :class, <<-end_eval, __FILE__, __LINE__ + 1
     def state_machine_name
       "State"
     end
   end_eval