Class: Likes::Like
- Inherits:
-
Object
- Object
- Likes::Like
- Defined in:
- lib/likes/like.rb
Overview
Job: Understands relation between person and the item they like
Instance Method Summary collapse
-
#==(other) ⇒ TrueClass, FalseClass
Tests other object for equality with itself.
- #add_item_to_map(map) ⇒ Object
- #add_person_to_map(map) ⇒ Object
-
#initialize(attributes = {}) ⇒ Like
constructor
Creates new instance of Like.
Constructor Details
#initialize(attributes = {}) ⇒ Like
Creates new instance of Like
9 10 11 12 |
# File 'lib/likes/like.rb', line 9 def initialize(attributes={}) @person = fetch_required_attribute(attributes, :person) @item = fetch_required_attribute(attributes, :item) end |
Instance Method Details
#==(other) ⇒ TrueClass, FalseClass
Tests other object for equality with itself. Objects of type different from Like are considered non-equal.
20 21 22 23 24 |
# File 'lib/likes/like.rb', line 20 def ==(other) return false unless Like === other self.person == other.person && self.item == other.item end |
#add_item_to_map(map) ⇒ Object
27 28 29 |
# File 'lib/likes/like.rb', line 27 def add_item_to_map(map) (map[person] ||= []) << item end |
#add_person_to_map(map) ⇒ Object
32 33 34 |
# File 'lib/likes/like.rb', line 32 def add_person_to_map(map) (map[item] ||= []) << person end |