Class: Proposer
- Inherits:
-
Object
- Object
- Proposer
- Defined in:
- lib/gale_shapley/proposer.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #current_acceptor_name ⇒ Object
- #engage ⇒ Object
- #free ⇒ Object
-
#initialize(name, preferences) ⇒ Proposer
constructor
A new instance of Proposer.
- #propose(acceptor) ⇒ Object
- #unengaged? ⇒ Boolean
Constructor Details
#initialize(name, preferences) ⇒ Proposer
Returns a new instance of Proposer.
6 7 8 9 10 11 |
# File 'lib/gale_shapley/proposer.rb', line 6 def initialize(name, preferences) @name = name @preferences = preferences @index = 0 @engaged = false end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/gale_shapley/proposer.rb', line 4 def name @name end |
Instance Method Details
#current_acceptor_name ⇒ Object
21 22 23 |
# File 'lib/gale_shapley/proposer.rb', line 21 def current_acceptor_name @preferences[@index] end |
#engage ⇒ Object
17 18 19 |
# File 'lib/gale_shapley/proposer.rb', line 17 def engage @engaged = true end |
#free ⇒ Object
33 34 35 36 |
# File 'lib/gale_shapley/proposer.rb', line 33 def free @index += 1 @engaged = false end |
#propose(acceptor) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/gale_shapley/proposer.rb', line 25 def propose(acceptor) if acceptor.engaged? acceptor.more_attractive?(self) ? acceptor.engage(self) : free else acceptor.engage(self) end end |
#unengaged? ⇒ Boolean
13 14 15 |
# File 'lib/gale_shapley/proposer.rb', line 13 def unengaged? !@engaged end |