moody 0.1 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,9 +4,8 @@ Moody: An implementation of the State Pattern in ruby
4
4
  This is an object-oriented way to represent Finite State Machines, where an
5
5
  object can change its behavior at runtime, depending on its internal state.
6
6
 
7
- If you want more information about this pattern, read:
8
-
9
- http://sourcemaking.com/design_patterns/state
7
+ If you want more information about this pattern, read [the explanation by
8
+ SourceMaking](http://sourcemaking.com/design_patterns/state).
10
9
 
11
10
  For a stupid example of how you would use this, here's a traffic light:
12
11
 
@@ -50,7 +49,7 @@ For a stupid example of how you would use this, here's a traffic light:
50
49
  delegate_to_state :color, :next
51
50
  end
52
51
 
53
- traffic_light = TrafficLight.new
52
+ traffic_light - TrafficLight.new
54
53
 
55
54
  loop do
56
55
  puts traffic_light.color
@@ -58,13 +57,18 @@ For a stupid example of how you would use this, here's a traffic light:
58
57
  end
59
58
 
60
59
  Inspiration
61
- ===========
60
+ -----------
62
61
 
63
62
  This is a reimplementation of the State Pattern gem by Daniel Cadenas. Check out
64
- his implementation at http://github.com/dcadenas/state_pattern
63
+ his implementation at [http://github.com/dcadenas/state_pattern]().
64
+
65
+ Installing
66
+ ----------
67
+
68
+ gem install moody
65
69
 
66
70
  Contributing
67
- ============
71
+ ------------
68
72
 
69
73
  * Send a pull request.
70
74
  * Small, atomic commits, please.
@@ -72,7 +76,7 @@ Contributing
72
76
  * Bonus points if you add features on topic branches.
73
77
 
74
78
  License
75
- =======
79
+ -------
76
80
 
77
81
  Copyright Nicolás Sanguinetti <hi@nicolassanguinetti.info>
78
82
 
@@ -28,12 +28,14 @@ module Moody
28
28
  end
29
29
 
30
30
  class State
31
+ attr_reader :context
32
+
31
33
  def initialize(context)
32
- @_context = context
34
+ @context = context
33
35
  end
34
36
 
35
37
  def switch_to(next_state)
36
- @_context.state = next_state.new(@_context)
38
+ context.state = next_state.new(context)
37
39
  end
38
40
  end
39
41
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "moody"
3
- s.version = "0.1"
3
+ s.version = "0.1.1"
4
4
  s.date = "2010-10-23"
5
5
 
6
6
  s.description = "Simple and straightforward implementation of the state pattern, inspired by the StatePattern gem"
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
14
14
  s.has_rdoc = true
15
15
 
16
16
  s.files = %w[
17
- README
17
+ README.md
18
18
  moody.gemspec
19
19
  lib/moody.rb
20
20
  test/test_moody.rb
metadata CHANGED
@@ -5,7 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- version: "0.1"
8
+ - 1
9
+ version: 0.1.1
9
10
  platform: ruby
10
11
  authors:
11
12
  - "Nicol\xC3\xA1s Sanguinetti"
@@ -26,7 +27,7 @@ extensions: []
26
27
  extra_rdoc_files: []
27
28
 
28
29
  files:
29
- - README
30
+ - README.md
30
31
  - moody.gemspec
31
32
  - lib/moody.rb
32
33
  - test/test_moody.rb