Class List Method List File List

# Class: Vehicle

Inherits:
  Object
  - Object
  - Vehicle
  show all
Defined in:
  vehicle.rb

## Direct Known Subclasses

Car

## State Machines

This class contains 1 state machine(s).

### state

## Instance Attribute Summary (collapse)

- - (Object) state

  Gets the current attribute value for the machine.

## Class Method Summary (collapse)

- + (String) human_state_event_name(event)

  Gets the humanized name for the given event.

- + (String) human_state_name(state)

  Gets the humanized name for the given state.

## Instance Method Summary (collapse)

- - (Boolean) can_crash?(requirements = {})

  Checks whether :crash can be fired.

- - (Boolean) can_idle?(requirements = {})

  Checks whether :idle can be fired.

- - (Boolean) can_ignite?(requirements = {})

  Checks whether :ignite can be fired.

- - (Boolean) can_park?(requirements = {})

  Checks whether :park can be fired.

- - (Boolean) can_repair?(requirements = {})

  Checks whether :repair can be fired.

- - (Boolean) can_shift_down?(requirements = {})

  Checks whether :shift_down can be fired.

- - (Boolean) can_shift_up?(requirements = {})

  Checks whether :shift_up can be fired.

- - (Boolean) crash(*args)

  Fires the :crash event.

- - (Boolean) crash!(*args)

  Fires the :crash event, raising an exception if it fails.

- - (StateMachine::Transition) crash_transition(requirements = {})

  Gets the next transition that would be performed if :crash were to be fired.

- - (Boolean) fire_state_event(event, *args)

  Fires an arbitrary state event with the given argument list.

- - (Boolean) first_gear?

  Checks whether :first_gear is the current state.

- - (String) human_state_name

  Gets the human-readable name of the state for the current value.

- - (Boolean) idle(*args)

  Fires the :idle event.

- - (Boolean) idle!(*args)

  Fires the :idle event, raising an exception if it fails.

- - (StateMachine::Transition) idle_transition(requirements = {})

  Gets the next transition that would be performed if :idle were to be fired.

- - (Boolean) idling?

  Checks whether :idling is the current state.

- - (Boolean) ignite(*args)

  Fires the :ignite event.

- - (Boolean) ignite!(*args)

  Fires the :ignite event, raising an exception if it fails.

- - (StateMachine::Transition) ignite_transition(requirements = {})

  Gets the next transition that would be performed if :ignite were to be fired.

- - (Boolean) park(*args)

  Fires the :park event.

- - (Boolean) park!(*args)

  Fires the :park event, raising an exception if it fails.

- - (StateMachine::Transition) park_transition(requirements = {})

  Gets the next transition that would be performed if :park were to be fired.

- - (Boolean) parked?

  Checks whether :parked is the current state.

- - (Boolean) repair(*args)

  Fires the :repair event.

- - (Boolean) repair!(*args)

  Fires the :repair event, raising an exception if it fails.

- - (StateMachine::Transition) repair_transition(requirements = {})

  Gets the next transition that would be performed if :repair were to be fired.

- - (Boolean) second_gear?

  Checks whether :second_gear is the current state.

- - (Boolean) shift_down(*args)

  Fires the :shift_down event.

- - (Boolean) shift_down!(*args)

  Fires the :shift_down event, raising an exception if it fails.

- - (StateMachine::Transition) shift_down_transition(requirements = {})

  Gets the next transition that would be performed if :shift_down were to be fired.

- - (Boolean) shift_up(*args)

  Fires the :shift_up event.

- - (Boolean) shift_up!(*args)

  Fires the :shift_up event, raising an exception if it fails.

- - (StateMachine::Transition) shift_up_transition(requirements = {})

  Gets the next transition that would be performed if :shift_up were to be fired.

- - (Boolean) stalled?

  Checks whether :stalled is the current state.

- - (Boolean) state?(state_name)

  Checks the given state name against the current state.

- - (Array<Symbol>) state_events(requirements = {})

  Gets the list of events that can be fired on the current state (uses the unqualified event names).

- - (Symbol) state_name

  Gets the internal name of the state for the current value.

- - (StateMachine::PathCollection) state_paths(requirements = {})

  Gets the list of sequences of transitions that can be run for the current state.

- - (Array<StateMachine::Transition>) state_transitions(requirements = {})

  Gets the list of transitions that can be made for the current state.

- - (Boolean) third_gear?

  Checks whether :third_gear is the current state.

## Instance Attribute Details

- (`Object`) state

Gets the current attribute value for the machine

### Returns:

- The attribute value

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

## Class Method Details

+ (`String`) human_state_event_name(event)

Gets the humanized name for the given event.

### Parameters:

- event (`Symbol`) —

  The event to look up

### Returns:

- (`String`) —

  The human event name

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

+ (`String`) human_state_name(state)

Gets the humanized name for the given state.

### Parameters:

- state (`Symbol`) —

  The state to look up

### Returns:

- (`String`) —

  The human state name

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

## Instance Method Details

- (`Boolean`) can_crash?(requirements = {})

Checks whether :crash can be fired.

### Parameters:

- requirements (`Hash`) (defaults to: `{}`) —

  The transition requirements to test against

### Options Hash (`requirements`):

- :from (`Symbol`) — default: `the current state` —

  One or more initial states

- :to (`Symbol`) —

  One or more target states

- :guard (`Boolean`) —

  Whether to guard transitions with conditionals

### Returns:

- (`Boolean`) —

  `true` if :crash can be fired, otherwise `false`

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`Boolean`) can_idle?(requirements = {})

Checks whether :idle can be fired.

### Parameters:

- requirements (`Hash`) (defaults to: `{}`) —

  The transition requirements to test against

### Options Hash (`requirements`):

- :from (`Symbol`) — default: `the current state` —

  One or more initial states

- :to (`Symbol`) —

  One or more target states

- :guard (`Boolean`) —

  Whether to guard transitions with conditionals

### Returns:

- (`Boolean`) —

  `true` if :idle can be fired, otherwise `false`

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`Boolean`) can_ignite?(requirements = {})

Checks whether :ignite can be fired.

### Parameters:

- requirements (`Hash`) (defaults to: `{}`) —

  The transition requirements to test against

### Options Hash (`requirements`):

- :from (`Symbol`) — default: `the current state` —

  One or more initial states

- :to (`Symbol`) —

  One or more target states

- :guard (`Boolean`) —

  Whether to guard transitions with conditionals

### Returns:

- (`Boolean`) —

  `true` if :ignite can be fired, otherwise `false`

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`Boolean`) can_park?(requirements = {})

Checks whether :park can be fired.

### Parameters:

- requirements (`Hash`) (defaults to: `{}`) —

  The transition requirements to test against

### Options Hash (`requirements`):

- :from (`Symbol`) — default: `the current state` —

  One or more initial states

- :to (`Symbol`) —

  One or more target states

- :guard (`Boolean`) —

  Whether to guard transitions with conditionals

### Returns:

- (`Boolean`) —

  `true` if :park can be fired, otherwise `false`

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`Boolean`) can_repair?(requirements = {})

Checks whether :repair can be fired.

### Parameters:

- requirements (`Hash`) (defaults to: `{}`) —

  The transition requirements to test against

### Options Hash (`requirements`):

- :from (`Symbol`) — default: `the current state` —

  One or more initial states

- :to (`Symbol`) —

  One or more target states

- :guard (`Boolean`) —

  Whether to guard transitions with conditionals

### Returns:

- (`Boolean`) —

  `true` if :repair can be fired, otherwise `false`

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`Boolean`) can_shift_down?(requirements = {})

Checks whether :shift_down can be fired.

### Parameters:

- requirements (`Hash`) (defaults to: `{}`) —

  The transition requirements to test against

### Options Hash (`requirements`):

- :from (`Symbol`) — default: `the current state` —

  One or more initial states

- :to (`Symbol`) —

  One or more target states

- :guard (`Boolean`) —

  Whether to guard transitions with conditionals

### Returns:

- (`Boolean`) —

  `true` if :shift_down can be fired, otherwise `false`

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`Boolean`) can_shift_up?(requirements = {})

Checks whether :shift_up can be fired.

### Parameters:

- requirements (`Hash`) (defaults to: `{}`) —

  The transition requirements to test against

### Options Hash (`requirements`):

- :from (`Symbol`) — default: `the current state` —

  One or more initial states

- :to (`Symbol`) —

  One or more target states

- :guard (`Boolean`) —

  Whether to guard transitions with conditionals

### Returns:

- (`Boolean`) —

  `true` if :shift_up can be fired, otherwise `false`

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`Boolean`) crash(*args)

Fires the :crash event.

### Parameters:

- args (`Array`) —

  Optional arguments to include in transition callbacks

### Returns:

- (`Boolean`) —

  `true` if the transition succeeds, otherwise `false`

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`Boolean`) crash!(*args)

Fires the :crash event, raising an exception if it fails.

### Parameters:

- args (`Array`) —

  Optional arguments to include in transition callbacks

### Returns:

- (`Boolean`) —

  `true` if the transition succeeds

### Raises:

- (`StateMachine::InvalidTransition`) —

  If the transition fails

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`StateMachine::Transition`) crash_transition(requirements = {})

Gets the next transition that would be performed if :crash were to be fired.

### Parameters:

- requirements (`Hash`) (defaults to: `{}`) —

  The transition requirements to test against

### Options Hash (`requirements`):

- :from (`Symbol`) — default: `the current state` —

  One or more initial states

- :to (`Symbol`) —

  One or more target states

- :guard (`Boolean`) —

  Whether to guard transitions with conditionals

### Returns:

- (`StateMachine::Transition`) —

  The transition that would be performed or `nil`

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`Boolean`) fire_state_event(event, *args)

Fires an arbitrary state event with the given argument list

### Parameters:

- event (`Symbol`) —

  The name of the event to fire

- args —

  Optional arguments to include in the transition

### Returns:

- (`Boolean`) —

  `true` if the event succeeds, otherwise `false`

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`Boolean`) first_gear?

Checks whether :first_gear is the current state.

### Returns:

- (`Boolean`) —

  `true` if this is the current state, otherwise `false`

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`String`) human_state_name

Gets the human-readable name of the state for the current value.

### Returns:

- (`String`) —

  The human-readable state name

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`Boolean`) idle(*args)

Fires the :idle event.

### Parameters:

- args (`Array`) —

  Optional arguments to include in transition callbacks

### Returns:

- (`Boolean`) —

  `true` if the transition succeeds, otherwise `false`

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`Boolean`) idle!(*args)

Fires the :idle event, raising an exception if it fails.

### Parameters:

- args (`Array`) —

  Optional arguments to include in transition callbacks

### Returns:

- (`Boolean`) —

  `true` if the transition succeeds

### Raises:

- (`StateMachine::InvalidTransition`) —

  If the transition fails

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`StateMachine::Transition`) idle_transition(requirements = {})

Gets the next transition that would be performed if :idle were to be fired.

### Parameters:

- requirements (`Hash`) (defaults to: `{}`) —

  The transition requirements to test against

### Options Hash (`requirements`):

- :from (`Symbol`) — default: `the current state` —

  One or more initial states

- :to (`Symbol`) —

  One or more target states

- :guard (`Boolean`) —

  Whether to guard transitions with conditionals

### Returns:

- (`StateMachine::Transition`) —

  The transition that would be performed or `nil`

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`Boolean`) idling?

Checks whether :idling is the current state.

### Returns:

- (`Boolean`) —

  `true` if this is the current state, otherwise `false`

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`Boolean`) ignite(*args)

Fires the :ignite event.

### Parameters:

- args (`Array`) —

  Optional arguments to include in transition callbacks

### Returns:

- (`Boolean`) —

  `true` if the transition succeeds, otherwise `false`

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`Boolean`) ignite!(*args)

Fires the :ignite event, raising an exception if it fails.

### Parameters:

- args (`Array`) —

  Optional arguments to include in transition callbacks

### Returns:

- (`Boolean`) —

  `true` if the transition succeeds

### Raises:

- (`StateMachine::InvalidTransition`) —

  If the transition fails

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`StateMachine::Transition`) ignite_transition(requirements = {})

Gets the next transition that would be performed if :ignite were to be fired.

### Parameters:

- requirements (`Hash`) (defaults to: `{}`) —

  The transition requirements to test against

### Options Hash (`requirements`):

- :from (`Symbol`) — default: `the current state` —

  One or more initial states

- :to (`Symbol`) —

  One or more target states

- :guard (`Boolean`) —

  Whether to guard transitions with conditionals

### Returns:

- (`StateMachine::Transition`) —

  The transition that would be performed or `nil`

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`Boolean`) park(*args)

Fires the :park event.

### Parameters:

- args (`Array`) —

  Optional arguments to include in transition callbacks

### Returns:

- (`Boolean`) —

  `true` if the transition succeeds, otherwise `false`

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`Boolean`) park!(*args)

Fires the :park event, raising an exception if it fails.

### Parameters:

- args (`Array`) —

  Optional arguments to include in transition callbacks

### Returns:

- (`Boolean`) —

  `true` if the transition succeeds

### Raises:

- (`StateMachine::InvalidTransition`) —

  If the transition fails

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`StateMachine::Transition`) park_transition(requirements = {})

Gets the next transition that would be performed if :park were to be fired.

### Parameters:

- requirements (`Hash`) (defaults to: `{}`) —

  The transition requirements to test against

### Options Hash (`requirements`):

- :from (`Symbol`) — default: `the current state` —

  One or more initial states

- :to (`Symbol`) —

  One or more target states

- :guard (`Boolean`) —

  Whether to guard transitions with conditionals

### Returns:

- (`StateMachine::Transition`) —

  The transition that would be performed or `nil`

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`Boolean`) parked?

Checks whether :parked is the current state.

### Returns:

- (`Boolean`) —

  `true` if this is the current state, otherwise `false`

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`Boolean`) repair(*args)

Fires the :repair event.

### Parameters:

- args (`Array`) —

  Optional arguments to include in transition callbacks

### Returns:

- (`Boolean`) —

  `true` if the transition succeeds, otherwise `false`

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`Boolean`) repair!(*args)

Fires the :repair event, raising an exception if it fails.

### Parameters:

- args (`Array`) —

  Optional arguments to include in transition callbacks

### Returns:

- (`Boolean`) —

  `true` if the transition succeeds

### Raises:

- (`StateMachine::InvalidTransition`) —

  If the transition fails

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`StateMachine::Transition`) repair_transition(requirements = {})

Gets the next transition that would be performed if :repair were to be fired.

### Parameters:

- requirements (`Hash`) (defaults to: `{}`) —

  The transition requirements to test against

### Options Hash (`requirements`):

- :from (`Symbol`) — default: `the current state` —

  One or more initial states

- :to (`Symbol`) —

  One or more target states

- :guard (`Boolean`) —

  Whether to guard transitions with conditionals

### Returns:

- (`StateMachine::Transition`) —

  The transition that would be performed or `nil`

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`Boolean`) second_gear?

Checks whether :second_gear is the current state.

### Returns:

- (`Boolean`) —

  `true` if this is the current state, otherwise `false`

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`Boolean`) shift_down(*args)

Fires the :shift_down event.

### Parameters:

- args (`Array`) —

  Optional arguments to include in transition callbacks

### Returns:

- (`Boolean`) —

  `true` if the transition succeeds, otherwise `false`

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`Boolean`) shift_down!(*args)

Fires the :shift_down event, raising an exception if it fails.

### Parameters:

- args (`Array`) —

  Optional arguments to include in transition callbacks

### Returns:

- (`Boolean`) —

  `true` if the transition succeeds

### Raises:

- (`StateMachine::InvalidTransition`) —

  If the transition fails

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`StateMachine::Transition`) shift_down_transition(requirements = {})

Gets the next transition that would be performed if :shift_down were to be fired.

### Parameters:

- requirements (`Hash`) (defaults to: `{}`) —

  The transition requirements to test against

### Options Hash (`requirements`):

- :from (`Symbol`) — default: `the current state` —

  One or more initial states

- :to (`Symbol`) —

  One or more target states

- :guard (`Boolean`) —

  Whether to guard transitions with conditionals

### Returns:

- (`StateMachine::Transition`) —

  The transition that would be performed or `nil`

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`Boolean`) shift_up(*args)

Fires the :shift_up event.

### Parameters:

- args (`Array`) —

  Optional arguments to include in transition callbacks

### Returns:

- (`Boolean`) —

  `true` if the transition succeeds, otherwise `false`

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`Boolean`) shift_up!(*args)

Fires the :shift_up event, raising an exception if it fails.

### Parameters:

- args (`Array`) —

  Optional arguments to include in transition callbacks

### Returns:

- (`Boolean`) —

  `true` if the transition succeeds

### Raises:

- (`StateMachine::InvalidTransition`) —

  If the transition fails

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`StateMachine::Transition`) shift_up_transition(requirements = {})

Gets the next transition that would be performed if :shift_up were to be fired.

### Parameters:

- requirements (`Hash`) (defaults to: `{}`) —

  The transition requirements to test against

### Options Hash (`requirements`):

- :from (`Symbol`) — default: `the current state` —

  One or more initial states

- :to (`Symbol`) —

  One or more target states

- :guard (`Boolean`) —

  Whether to guard transitions with conditionals

### Returns:

- (`StateMachine::Transition`) —

  The transition that would be performed or `nil`

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`Boolean`) stalled?

Checks whether :stalled is the current state.

### Returns:

- (`Boolean`) —

  `true` if this is the current state, otherwise `false`

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`Boolean`) state?(state_name)

Checks the given state name against the current state.

### Parameters:

- state_name (`Symbol`) —

  The name of the state to check

### Returns:

- (`Boolean`) —

  True if they are the same state, otherwise false

### Raises:

- (`IndexError`) —

  If the state name is invalid

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`Array<Symbol>`) state_events(requirements = {})

Gets the list of events that can be fired on the current state (uses the unqualified event names)

### Parameters:

- requirements (`Hash`) (defaults to: `{}`) —

  The transition requirements to test against

### Options Hash (`requirements`):

- :from (`Symbol`) — default: `the current state` —

  One or more initial states

- :to (`Symbol`) —

  One or more target states

- :on (`Symbol`) —

  One or more events that fire the transition

- :guard (`Boolean`) —

  Whether to guard transitions with conditionals

### Returns:

- (`Array<Symbol>`) —

  The list of event names

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`Symbol`) state_name

Gets the internal name of the state for the current value.

### Returns:

- (`Symbol`) —

  The internal name of the state

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`StateMachine::PathCollection`) state_paths(requirements = {})

Gets the list of sequences of transitions that can be run for the current state

### Parameters:

- requirements (`Hash`) (defaults to: `{}`) —

  The transition requirements to test against

### Options Hash (`requirements`):

- :from (`Symbol`) — default: `the current state` —

  The initial state

- :to (`Symbol`) —

  The target state

- :deep (`Boolean`) —

  Whether to enable deep searches for the target state

- :guard (`Boolean`) —

  Whether to guard transitions with conditionals

### Returns:

- (`StateMachine::PathCollection`) —

  The collection of paths

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`Array<StateMachine::Transition>`) state_transitions(requirements = {})

Gets the list of transitions that can be made for the current state

### Parameters:

- requirements (`Hash`) (defaults to: `{}`) —

  The transition requirements to test against

### Options Hash (`requirements`):

- :from (`Symbol`) — default: `the current state` —

  One or more initial states

- :to (`Symbol`) —

  One or more target states

- :on (`Symbol`) —

  One or more events that fire the transition

- :guard (`Boolean`) —

  Whether to guard transitions with conditionals

### Returns:

- (`Array<StateMachine::Transition>`) —

  The available transitions

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end

- (`Boolean`) third_gear?

Checks whether :third_gear is the current state.

### Returns:

- (`Boolean`) —

  `true` if this is the current state, otherwise `false`

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

    # File 'vehicle.rb', line 4

    state_machine :initial => :parked do
      event :park do
        transition [:idling, :first_gear] => :parked
      end

      event :ignite do
        transition :stalled => same, :parked => :idling
      end

      event :idle do
        transition :first_gear => :idling
      end

      event :shift_up do
        transition :idling => :first_gear, :first_gear => :second_gear, :second_gear => :third_gear
      end

      event :shift_down do
        transition :third_gear => :second_gear, :second_gear => :first_gear
      end

      event :crash do
        transition [:first_gear, :second_gear, :third_gear] => :stalled
      end

      event :repair do
        transition :stalled => :parked
      end
    end