Class: Primitive::Entity
- Inherits:
-
Object
- Object
- Primitive::Entity
- Extended by:
- T::Sig
- Includes:
- Comparable
- Defined in:
- lib/primitive/entity.rb
Overview
Base class for uniquely identifiable classes. Subclasses are simply based on a string-based ID and comparison/sorting/equality will be done in a case-insensitive manner.
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object (also: #eql?)
- #comparable_id ⇒ Object
- #hash ⇒ Object
-
#initialize(id = '') ⇒ Entity
constructor
A new instance of Entity.
- #to_s ⇒ Object
Constructor Details
#initialize(id = '') ⇒ Entity
Returns a new instance of Entity.
15 16 17 |
# File 'lib/primitive/entity.rb', line 15 def initialize(id = '') @id = id end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
12 13 14 |
# File 'lib/primitive/entity.rb', line 12 def id @id end |
Instance Method Details
#<=>(other) ⇒ Object
20 21 22 |
# File 'lib/primitive/entity.rb', line 20 def <=>(other) comparable_id <=> other.comparable_id end |
#==(other) ⇒ Object Also known as: eql?
25 26 27 |
# File 'lib/primitive/entity.rb', line 25 def ==(other) comparable_id == other.comparable_id end |
#comparable_id ⇒ Object
41 42 43 |
# File 'lib/primitive/entity.rb', line 41 def comparable_id id.upcase end |
#hash ⇒ Object
31 32 33 |
# File 'lib/primitive/entity.rb', line 31 def hash comparable_id.hash end |
#to_s ⇒ Object
36 37 38 |
# File 'lib/primitive/entity.rb', line 36 def to_s id end |