surrogate 0.5.5 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,41 +0,0 @@
1
- require 'bindable_block'
2
-
3
- class Surrogate
4
- class Options
5
- attr_accessor :options, :default_proc
6
-
7
- def initialize(options, default_proc)
8
- self.options, self.default_proc = options, default_proc
9
- end
10
-
11
- def has?(name)
12
- options.has_key? name
13
- end
14
-
15
- def [](key)
16
- options[key]
17
- end
18
-
19
- def to_hash
20
- options
21
- end
22
-
23
- def default(instance, invocation, &no_default)
24
- if options.has_key? :default
25
- options[:default]
26
- elsif default_proc
27
- # This works for now, but it's a kind of crappy solution because
28
- # BindableBlock adds and removes methods for each time it is invoked.
29
- #
30
- # A better solution would be to instantiate it before passing it to
31
- # the options, then we only have to bind it to an instance and invoke
32
- BindableBlock.new(instance.class, &default_proc)
33
- .bind(instance)
34
- .call(*invocation.args, &invocation.block)
35
- else
36
- no_default.call
37
- end
38
- end
39
- end
40
- end
41
-