Class: OpenObject

Inherits:
Object show all
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

Methods included from Enumerable

#find_with_value, #grep2, #mm, #to_proc

Class Method Details

.inherited(*args, **kwds, &blk) ⇒ Object

Raises:

  • (RuntimeError)


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

.merging(*args) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/lab42/core/open_object.rb', line 46

def merging *args
  new **(
    args.inject Hash.new do |r, arg|
      r.merge arg.to_hash
    end
  )
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_hashObject



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