Class: Surrogate::Options
- Inherits:
-
Object
- Object
- Surrogate::Options
- Defined in:
- lib/surrogate/options.rb
Instance Attribute Summary collapse
-
#default_proc ⇒ Object
Returns the value of attribute default_proc.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #default(instance, invocation, &no_default) ⇒ Object
- #has?(name) ⇒ Boolean
-
#initialize(options, default_proc) ⇒ Options
constructor
A new instance of Options.
- #to_hash ⇒ Object
Constructor Details
#initialize(options, default_proc) ⇒ Options
Returns a new instance of Options.
7 8 9 |
# File 'lib/surrogate/options.rb', line 7 def initialize(, default_proc) self., self.default_proc = , default_proc end |
Instance Attribute Details
#default_proc ⇒ Object
Returns the value of attribute default_proc.
5 6 7 |
# File 'lib/surrogate/options.rb', line 5 def default_proc @default_proc end |
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/surrogate/options.rb', line 5 def @options end |
Instance Method Details
#[](key) ⇒ Object
15 16 17 |
# File 'lib/surrogate/options.rb', line 15 def [](key) [key] end |
#default(instance, invocation, &no_default) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/surrogate/options.rb', line 23 def default(instance, invocation, &no_default) if .has_key? :default [:default] elsif default_proc # This works for now, but it's a kind of crappy solution because # BindableBlock adds and removes methods for each time it is invoked. # # A better solution would be to instantiate it before passing it to # the options, then we only have to bind it to an instance and invoke BindableBlock.new(instance.class, &default_proc) .bind(instance) .call(*invocation.args, &invocation.block) else no_default.call end end |
#has?(name) ⇒ Boolean
11 12 13 |
# File 'lib/surrogate/options.rb', line 11 def has?(name) .has_key? name end |
#to_hash ⇒ Object
19 20 21 |
# File 'lib/surrogate/options.rb', line 19 def to_hash end |