Module: Stateology
- Defined in:
- lib/stateology.rb
Defined Under Namespace
Modules: SM_Class_Methods
Constant Summary collapse
- VERSION =
"0.1.8"
- Default =
alternative to ‘nil’
nil
Class Method Summary collapse
-
.included(c) ⇒ Object
bring in class methods on include.
Instance Method Summary collapse
- #state(*state_args, &block) ⇒ Object
-
#state?(state_name) ⇒ Boolean
is the current state equal to state_name?.
-
#state_mod ⇒ Object
return the current state as a module.
Class Method Details
.included(c) ⇒ Object
bring in class methods on include
20 21 22 |
# File 'lib/stateology.rb', line 20 def self.included(c) c.extend(SM_Class_Methods) end |
Instance Method Details
#state(*state_args, &block) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/stateology.rb', line 151 def state(*state_args, &block) # behave as getter if state_args.empty? then return __state_getter end new_state = __validate_state_name(state_args.first) __state_transition(new_state, state_args, &block) # return value is the current state __current_state rescue NameError raise NameError, "#{new_state} not a valid state" end |
#state?(state_name) ⇒ Boolean
is the current state equal to state_name?
171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/stateology.rb', line 171 def state?(state_name) state_name = __validate_state_name(state_name) # compare state_name == __current_state rescue NameError raise NameError, "#{state_name} not a valid state" end |
#state_mod ⇒ Object
return the current state as a module
184 185 186 |
# File 'lib/stateology.rb', line 184 def state_mod __current_state end |