Class: ColorCalculator::Clump::Abstract
- Inherits:
-
Object
- Object
- ColorCalculator::Clump::Abstract
- Defined in:
- lib/color_calculator/clump/abstract.rb
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(*attributes) ⇒ Abstract
constructor
A new instance of Abstract.
- #inspect ⇒ Object (also: #to_s)
- #to_h ⇒ Object
Constructor Details
#initialize(*attributes) ⇒ Abstract
8 9 10 11 12 13 14 15 16 |
# File 'lib/color_calculator/clump/abstract.rb', line 8 def initialize(*attributes) self.class.attributes.each.with_index do |name, index| instance_variable_set("@#{name}".to_sym, attributes[index]) define_singleton_method(name) do instance_variable_get("@#{name}".to_sym) end end end |
Instance Method Details
#==(other) ⇒ Object
24 25 26 27 28 |
# File 'lib/color_calculator/clump/abstract.rb', line 24 def ==(other) raise UnlikeComparisonError if self.class != other.class to_h == other.to_h end |
#inspect ⇒ Object Also known as: to_s
30 31 32 |
# File 'lib/color_calculator/clump/abstract.rb', line 30 def inspect to_h.to_s end |
#to_h ⇒ Object
18 19 20 21 22 |
# File 'lib/color_calculator/clump/abstract.rb', line 18 def to_h self.class.attributes.reduce({}) do |memo, | memo.merge( => public_send()) end end |