Class: OpenObject
- Inherits:
-
Object
- Object
- OpenObject
- Extended by:
- Forwarder
- Includes:
- Enumerable
- Defined in:
- lib/lab42/core/open_object.rb
Overview
require ‘lab42/core/open_object/transformations’
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #each(&blk) ⇒ Object
- #to_hash ⇒ Object
- #update(**params) ⇒ Object (also: #merge)
Methods included from Enumerable
Class Method Details
.inherited(*args, **kwds, &blk) ⇒ Object
42 43 44 |
# File 'lib/lab42/core/open_object.rb', line 42 def inherited *args, **kwds, &blk raise RuntimeError, "I prefer delegation to inheritance, if you do not, MP me" end |
Instance Method Details
#==(other) ⇒ Object
12 13 14 |
# File 'lib/lab42/core/open_object.rb', line 12 def == other self.class === other && to_hash == other.to_hash end |
#each(&blk) ⇒ Object
15 16 17 18 19 |
# File 'lib/lab42/core/open_object.rb', line 15 def each &blk @data.each do | k, v | blk.( self.class.new k => v ) end end |
#to_hash ⇒ Object
21 22 23 |
# File 'lib/lab42/core/open_object.rb', line 21 def to_hash @data.clone end |
#update(**params) ⇒ Object Also known as: merge
24 25 26 27 |
# File 'lib/lab42/core/open_object.rb', line 24 def update **params new_params = @data.merge params self.class.new( **new_params ) end |