Class: Acceptor
- Inherits:
-
Object
- Object
- Acceptor
- Defined in:
- lib/gale_shapley/acceptor.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#proposer ⇒ Object
Returns the value of attribute proposer.
Instance Method Summary collapse
- #engage(proposer) ⇒ Object
- #engaged? ⇒ Boolean
-
#initialize(name, preferences) ⇒ Acceptor
constructor
A new instance of Acceptor.
- #more_attractive?(proposer) ⇒ Boolean
Constructor Details
#initialize(name, preferences) ⇒ Acceptor
Returns a new instance of Acceptor.
6 7 8 9 10 |
# File 'lib/gale_shapley/acceptor.rb', line 6 def initialize(name, preferences) @name = name @preferences = preferences @proposer = nil end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/gale_shapley/acceptor.rb', line 4 def name @name end |
#proposer ⇒ Object
Returns the value of attribute proposer.
4 5 6 |
# File 'lib/gale_shapley/acceptor.rb', line 4 def proposer @proposer end |
Instance Method Details
#engage(proposer) ⇒ Object
16 17 18 19 20 |
# File 'lib/gale_shapley/acceptor.rb', line 16 def engage(proposer) @proposer&.free @proposer = proposer @proposer.engage end |
#engaged? ⇒ Boolean
12 13 14 |
# File 'lib/gale_shapley/acceptor.rb', line 12 def engaged? !!@proposer end |
#more_attractive?(proposer) ⇒ Boolean
22 23 24 |
# File 'lib/gale_shapley/acceptor.rb', line 22 def more_attractive?(proposer) @preferences.index(proposer.name) < @preferences.index(@proposer.name) end |