adt 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +5 -0
- data/lib/adt.rb +14 -7
- data/lib/adt/case_recorder.rb +1 -0
- metadata +12 -6
data/CHANGELOG.md
CHANGED
data/lib/adt.rb
CHANGED
@@ -220,16 +220,23 @@ module ADT
|
|
220
220
|
# @param [Proc] The definitions of the implementations for each case.
|
221
221
|
def operation(sym, &definitions)
|
222
222
|
define_method(sym) do |*args|
|
223
|
+
the_instance = self
|
223
224
|
dsl = CaseRecorder.new
|
224
|
-
|
225
|
-
#
|
226
|
-
|
227
|
-
# to the operation)
|
228
|
-
dsl_cls.send(:define_method, :_defs, &definitions)
|
229
|
-
dsl._defs(*args)
|
225
|
+
# The definitions block needs to be executed in the context of the recorder, to
|
226
|
+
# read the impls.
|
227
|
+
dsl.__instance_exec(*args, &definitions)
|
230
228
|
# Now we just turn the [(case_name, impl)] structure into an argument for fold and
|
231
229
|
# are done. Fold with a hash will check that all keys are defined.
|
232
|
-
fold(dsl._implementations.inject({}) { |memo, (c, impl)|
|
230
|
+
fold(dsl._implementations.inject({}) { |memo, (c, impl)|
|
231
|
+
# Fucker. if 'impl' is used directly, because of the 'define_method' from earlier,
|
232
|
+
# it is evaluated in the context of the recorder, which is bad. So instead. We
|
233
|
+
# instance_exec it back on the instance.
|
234
|
+
# TODO: use the proc builder like in the `cases` method, which will let us tie
|
235
|
+
# down the arity
|
236
|
+
some_impl = proc { |*args| the_instance.instance_exec(*args, &impl) }
|
237
|
+
memo[c] = some_impl
|
238
|
+
memo
|
239
|
+
})
|
233
240
|
end
|
234
241
|
end
|
235
242
|
end
|
data/lib/adt/case_recorder.rb
CHANGED
metadata
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 4
|
9
|
+
version: 0.0.4
|
6
10
|
platform: ruby
|
7
11
|
authors:
|
8
12
|
- Nick Partridge
|
@@ -10,7 +14,7 @@ autorequire:
|
|
10
14
|
bindir: bin
|
11
15
|
cert_chain: []
|
12
16
|
|
13
|
-
date: 2011-
|
17
|
+
date: 2011-09-06 00:00:00 +10:00
|
14
18
|
default_executable:
|
15
19
|
dependencies: []
|
16
20
|
|
@@ -37,21 +41,23 @@ rdoc_options: []
|
|
37
41
|
require_paths:
|
38
42
|
- lib
|
39
43
|
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
-
none: false
|
41
44
|
requirements:
|
42
45
|
- - ">="
|
43
46
|
- !ruby/object:Gem::Version
|
47
|
+
segments:
|
48
|
+
- 0
|
44
49
|
version: "0"
|
45
50
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
-
none: false
|
47
51
|
requirements:
|
48
52
|
- - ">="
|
49
53
|
- !ruby/object:Gem::Version
|
54
|
+
segments:
|
55
|
+
- 0
|
50
56
|
version: "0"
|
51
57
|
requirements: []
|
52
58
|
|
53
59
|
rubyforge_project:
|
54
|
-
rubygems_version: 1.6
|
60
|
+
rubygems_version: 1.3.6
|
55
61
|
signing_key:
|
56
62
|
specification_version: 3
|
57
63
|
summary: Algebraic data type DSL
|