Class: CIAT::TrafficLight
- Inherits:
-
Object
- Object
- CIAT::TrafficLight
- Defined in:
- lib/ciat/traffic_light.rb
Constant Summary collapse
- GREEN =
CIAT::TrafficLight.new(:green)
- RED =
CIAT::TrafficLight.new(:red)
- YELLOW =
CIAT::TrafficLight.new(:yellow)
- UNSET =
CIAT::TrafficLight.new(:unset)
Instance Attribute Summary collapse
-
#setting ⇒ Object
readonly
Returns the value of attribute setting.
Instance Method Summary collapse
- #color ⇒ Object
-
#green! ⇒ Object
:nodoc:.
- #green? ⇒ Boolean
-
#initialize(setting = :unset) ⇒ TrafficLight
constructor
:nodoc:.
-
#red! ⇒ Object
:nodoc:.
- #red? ⇒ Boolean
- #unset? ⇒ Boolean
-
#yellow! ⇒ Object
:nodoc:.
- #yellow? ⇒ Boolean
Constructor Details
#initialize(setting = :unset) ⇒ TrafficLight
:nodoc:
5 6 7 |
# File 'lib/ciat/traffic_light.rb', line 5 def initialize(setting = :unset) #:nodoc: @setting = setting end |
Instance Attribute Details
#setting ⇒ Object (readonly)
Returns the value of attribute setting.
3 4 5 |
# File 'lib/ciat/traffic_light.rb', line 3 def setting @setting end |
Instance Method Details
#color ⇒ Object
42 43 44 |
# File 'lib/ciat/traffic_light.rb', line 42 def color @setting.to_s end |
#green! ⇒ Object
:nodoc:
22 23 24 |
# File 'lib/ciat/traffic_light.rb', line 22 def green! #:nodoc: @setting = :green unless yellow? end |
#green? ⇒ Boolean
18 19 20 |
# File 'lib/ciat/traffic_light.rb', line 18 def green? @setting == :green end |
#red! ⇒ Object
:nodoc:
38 39 40 |
# File 'lib/ciat/traffic_light.rb', line 38 def red! #:nodoc: @setting = :red unless yellow? end |
#red? ⇒ Boolean
34 35 36 |
# File 'lib/ciat/traffic_light.rb', line 34 def red? @setting == :red end |
#unset? ⇒ Boolean
14 15 16 |
# File 'lib/ciat/traffic_light.rb', line 14 def unset? @setting == :unset end |
#yellow! ⇒ Object
:nodoc:
30 31 32 |
# File 'lib/ciat/traffic_light.rb', line 30 def yellow! #:nodoc: @setting = :yellow end |
#yellow? ⇒ Boolean
26 27 28 |
# File 'lib/ciat/traffic_light.rb', line 26 def yellow? @setting == :yellow end |