Class: RFunk::Function
- Inherits:
-
Object
show all
- Defined in:
- lib/rfunk/attribute/function.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(this, function_definition, &block) ⇒ Function
Returns a new instance of Function.
5
6
7
8
9
10
|
# File 'lib/rfunk/attribute/function.rb', line 5
def initialize(this, function_definition, &block)
@this = this
@function_definition = function_definition
@block = block
@variables = {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *arguments, &block) ⇒ Object
54
55
56
|
# File 'lib/rfunk/attribute/function.rb', line 54
def method_missing(method, *arguments, &block)
this.send(method, *arguments, &block)
end
|
Instance Attribute Details
#this ⇒ Object
Returns the value of attribute this.
3
4
5
|
# File 'lib/rfunk/attribute/function.rb', line 3
def this
@this
end
|
Instance Method Details
#assert(&_) ⇒ Object
25
26
27
28
|
# File 'lib/rfunk/attribute/function.rb', line 25
def assert(&_)
return true if yield
raise RFunk::AssertionError
end
|
#body(&block) ⇒ Object
38
39
40
|
# File 'lib/rfunk/attribute/function.rb', line 38
def body(&block)
@body_block = block
end
|
#execute(*args) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/rfunk/attribute/function.rb', line 42
def execute(*args)
validate_parameter_types(*args)
return_value = instance_exec(*args, &block)
if body_block
execute_body_block
else
validate_return_type(return_value)
RFunk::Option(return_value)
end
end
|
#post(&block) ⇒ Object
34
35
36
|
# File 'lib/rfunk/attribute/function.rb', line 34
def post(&block)
@post_block = block
end
|
#pre(&block) ⇒ Object
30
31
32
|
# File 'lib/rfunk/attribute/function.rb', line 30
def pre(&block)
@pre_block = block
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
58
59
60
|
# File 'lib/rfunk/attribute/function.rb', line 58
def respond_to_missing?(method_name, include_private = false)
this.respond_to_missing?(method_name, include_private)
end
|
#var(options) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/rfunk/attribute/function.rb', line 12
def var(options)
if options.is_a?(Hash)
if variables.empty?
self.variables = options
else
error_checking.raise_immutable(options, variables)
self.variables = variables.merge(options)
end
else
RFunk::Some(RFunk::Some(variables)[options])
end
end
|