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
57
58
59
|
# File 'lib/rfunk/attribute/function.rb', line 57
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
27
28
29
30
31
|
# File 'lib/rfunk/attribute/function.rb', line 27
def assert(&_)
return true if yield
raise RFunk::AssertionError
end
|
#body(&block) ⇒ Object
41
42
43
|
# File 'lib/rfunk/attribute/function.rb', line 41
def body(&block)
@body_block = block
end
|
#execute(*args) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/rfunk/attribute/function.rb', line 45
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
37
38
39
|
# File 'lib/rfunk/attribute/function.rb', line 37
def post(&block)
@post_block = block
end
|
#pre(&block) ⇒ Object
33
34
35
|
# File 'lib/rfunk/attribute/function.rb', line 33
def pre(&block)
@pre_block = block
end
|
#val(options) ⇒ Object
Also known as:
let
12
13
14
15
16
17
18
19
|
# File 'lib/rfunk/attribute/function.rb', line 12
def val(options)
if variables.empty?
self.variables = options
else
error_checking.raise_immutable(options, variables)
self.variables = variables.merge(options)
end
end
|
#value(options) ⇒ Object
21
22
23
|
# File 'lib/rfunk/attribute/function.rb', line 21
def value(options)
RFunk.some(RFunk.some(variables)[options])
end
|