Class: SFRP::Mono::Memory

Inherits:
Object
  • Object
show all
Defined in:
lib/sfrp/mono/memory.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ Memory

Returns a new instance of Memory.



12
13
14
# File 'lib/sfrp/mono/memory.rb', line 12

def initialize(hash = {})
  @hash = hash
end

Class Method Details

.emptyObject



4
5
6
# File 'lib/sfrp/mono/memory.rb', line 4

def self.empty
  Memory.new
end

.one(type_str) ⇒ Object



8
9
10
# File 'lib/sfrp/mono/memory.rb', line 8

def self.one(type_str)
  Memory.new(type_str => 1)
end

Instance Method Details

#and(other) ⇒ Object



16
17
18
# File 'lib/sfrp/mono/memory.rb', line 16

def and(other)
  Memory.new(@hash.merge(other.hash) { |_, v1, v2| v1 + v2 })
end

#count(type_str) ⇒ Object



24
25
26
# File 'lib/sfrp/mono/memory.rb', line 24

def count(type_str)
  @hash[type_str] || 0
end

#or(other) ⇒ Object



20
21
22
# File 'lib/sfrp/mono/memory.rb', line 20

def or(other)
  Memory.new(@hash.merge(other.hash) { |_, v1, v2| [v1, v2].max })
end