Class: Manioc::Struct
- Inherits:
-
Object
- Object
- Manioc::Struct
- Defined in:
- lib/manioc/struct.rb
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(**fields) ⇒ Struct
constructor
A new instance of Struct.
- #inspect ⇒ Object
- #to_h ⇒ Object
- #with(**fields) ⇒ Object
Constructor Details
Instance Method Details
#==(other) ⇒ Object
33 34 35 |
# File 'lib/manioc/struct.rb', line 33 def == other super || to_h == other.to_h end |
#inspect ⇒ Object
45 46 47 48 49 |
# File 'lib/manioc/struct.rb', line 45 def inspect # :nocov: %|<#{self.class.name}(#{self.class.fields.join(', ')})>| # :nocov: end |
#to_h ⇒ Object
41 42 43 |
# File 'lib/manioc/struct.rb', line 41 def to_h self.class.fields.each_with_object({}) { |field,h| h[field] = public_send field } end |
#with(**fields) ⇒ Object
37 38 39 |
# File 'lib/manioc/struct.rb', line 37 def with **fields self.class.new to_h.merge fields end |