Class: Kumi::IR::Base::Module
- Inherits:
-
Object
- Object
- Kumi::IR::Base::Module
show all
- Defined in:
- lib/kumi/ir/base/module.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name:, functions: []) ⇒ Module
Returns a new instance of Module.
9
10
11
12
13
|
# File 'lib/kumi/ir/base/module.rb', line 9
def initialize(name:, functions: [])
@name = name.to_sym
@functions = {}
functions.each { |fn| add_function(fn) }
end
|
Instance Attribute Details
#functions ⇒ Object
Returns the value of attribute functions.
7
8
9
|
# File 'lib/kumi/ir/base/module.rb', line 7
def functions
@functions
end
|
#name ⇒ Object
Returns the value of attribute name.
7
8
9
|
# File 'lib/kumi/ir/base/module.rb', line 7
def name
@name
end
|
Instance Method Details
#add_function(fn) ⇒ Object
15
16
17
18
|
# File 'lib/kumi/ir/base/module.rb', line 15
def add_function(fn)
raise ArgumentError, "function required" unless fn.is_a?(Function)
@functions[fn.name] = fn
end
|
#each_function(&blk) ⇒ Object
24
25
26
|
# File 'lib/kumi/ir/base/module.rb', line 24
def each_function(&blk)
@functions.values.each(&blk)
end
|
#fetch_function(name, &blk) ⇒ Object
20
21
22
|
# File 'lib/kumi/ir/base/module.rb', line 20
def fetch_function(name, &blk)
@functions.fetch(name.to_sym, &blk)
end
|
#to_h ⇒ Object
28
29
30
31
32
33
|
# File 'lib/kumi/ir/base/module.rb', line 28
def to_h
{
name:,
functions: @functions.values.map(&:to_h)
}
end
|