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
19
|
# 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 ⇒ Object
25
26
27
|
# File 'lib/kumi/ir/base/module.rb', line 25
def each_function(&)
@functions.values.each(&)
end
|
#fetch_function(name) ⇒ Object
21
22
23
|
# File 'lib/kumi/ir/base/module.rb', line 21
def fetch_function(name, &)
@functions.fetch(name.to_sym, &)
end
|
#to_h ⇒ Object
29
30
31
32
33
34
|
# File 'lib/kumi/ir/base/module.rb', line 29
def to_h
{
name:,
functions: @functions.values.map(&:to_h)
}
end
|