Class List Method List File List

# Class: Car

Inherits:
  Vehicle
  - Object
  - Vehicle
  - Car
  show all
Defined in:
  car.rb

## State Machines

This class contains 1 state machine(s).

### state

## Instance Attribute Summary

### Attributes inherited from Vehicle

#state

## Instance Method Summary (collapse)

- - (Boolean) backing_up?

  Checks whether :backing_up is the current state.

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

  Checks whether :reverse can be fired.

- - (Boolean) reverse(*args)

  Fires the :reverse event.

- - (Boolean) reverse!(*args)

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

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

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

### Methods inherited from Vehicle

#can_crash?, #can_idle?, #can_ignite?, #can_park?, #can_repair?, #can_shift_down?, #can_shift_up?, #crash, #crash!, #crash_transition, #fire_state_event, #first_gear?, human_state_event_name, human_state_name, #human_state_name, #idle, #idle!, #idle_transition, #idling?, #ignite, #ignite!, #ignite_transition, #park, #park!, #park_transition, #parked?, #repair, #repair!, #repair_transition, #second_gear?, #shift_down, #shift_down!, #shift_down_transition, #shift_up, #shift_up!, #shift_up_transition, #stalled?, #state?, #state_events, #state_name, #state_paths, #state_transitions, #third_gear?

## Instance Method Details

- (`Boolean`) backing_up?

Checks whether :backing_up 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

    # File 'car.rb', line 4

    state_machine do
      event :reverse do
        transition [:parked, :idling, :first_gear] => :backing_up
      end

      event :park do
        transition :backing_up => :parked
      end

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

      event :shift_up do
        transition :backing_up => :first_gear
      end
    end

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

Checks whether :reverse 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 :reverse can be fired, otherwise `false`

    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20

    # File 'car.rb', line 4

    state_machine do
      event :reverse do
        transition [:parked, :idling, :first_gear] => :backing_up
      end

      event :park do
        transition :backing_up => :parked
      end

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

      event :shift_up do
        transition :backing_up => :first_gear
      end
    end

- (`Boolean`) reverse(*args)

Fires the :reverse 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

    # File 'car.rb', line 4

    state_machine do
      event :reverse do
        transition [:parked, :idling, :first_gear] => :backing_up
      end

      event :park do
        transition :backing_up => :parked
      end

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

      event :shift_up do
        transition :backing_up => :first_gear
      end
    end

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

Fires the :reverse 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

    # File 'car.rb', line 4

    state_machine do
      event :reverse do
        transition [:parked, :idling, :first_gear] => :backing_up
      end

      event :park do
        transition :backing_up => :parked
      end

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

      event :shift_up do
        transition :backing_up => :first_gear
      end
    end

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

Gets the next transition that would be performed if :reverse 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

    # File 'car.rb', line 4

    state_machine do
      event :reverse do
        transition [:parked, :idling, :first_gear] => :backing_up
      end

      event :park do
        transition :backing_up => :parked
      end

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

      event :shift_up do
        transition :backing_up => :first_gear
      end
    end