Sha256: 8263dc540a72a905b967e28a8f7b5a1b7e1c56b9dd6a5f16e40d8e4a5c3e7477
Contents?: true
Size: 771 Bytes
Versions: 1
Compression:
Stored size: 771 Bytes
Contents
require_relative 'version' class Minimus TransitionError = Class.new(StandardError) attr_reader :states, :initial_state attr_accessor :current_state def initialize(*states) @states = states @initial_state = states.first @current_state = initial_state end def move(new_state) return false unless move_possible?(new_state) self.current_state = new_state yield if block_given? end def move!(new_state) unless move_possible?(new_state) raise TransitionError, %Q{unallowed transition from #{current_state} to #{new_state}} end self.current_state = new_state yield if block_given? end private def move_possible?(new_state) states[states.index(current_state) + 1] == new_state end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
minimus-0.1.0 | lib/minimus.rb |