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, &block) ⇒ Function
Returns a new instance of Function.
5
6
7
8
9
|
# File 'lib/rfunk/attribute/function.rb', line 5
def initialize(this, &block)
@this = this
@block = block
@variables = {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *arguments, &block) ⇒ Object
66
67
68
|
# File 'lib/rfunk/attribute/function.rb', line 66
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
24
25
26
27
28
29
30
|
# File 'lib/rfunk/attribute/function.rb', line 24
def assert(&_)
if yield
true
else
raise AssertionError
end
end
|
#body(&block) ⇒ Object
40
41
42
|
# File 'lib/rfunk/attribute/function.rb', line 40
def body(&block)
@body_block = block
end
|
#execute(*args) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/rfunk/attribute/function.rb', line 44
def execute(*args)
result = instance_exec(*args, &block)
if body_block
if pre_block
instance_eval(&pre_block).tap { |r|
error_checking.raise_condition_error(PreConditionError, r)
}
end
Option(instance_eval(&body_block)).tap {
if post_block
instance_eval(&post_block).tap { |r|
error_checking.raise_condition_error(PostConditionError, r)
}
end
}
else
Option(result)
end
end
|
#post(&block) ⇒ Object
36
37
38
|
# File 'lib/rfunk/attribute/function.rb', line 36
def post(&block)
@post_block = block
end
|
#pre(&block) ⇒ Object
32
33
34
|
# File 'lib/rfunk/attribute/function.rb', line 32
def pre(&block)
@pre_block = block
end
|
#var(options) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/rfunk/attribute/function.rb', line 11
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
Some(Some(variables)[options])
end
end
|