Class: Surrogate::MethodDefinition
- Inherits:
-
Object
- Object
- Surrogate::MethodDefinition
- Defined in:
- lib/surrogate/method_definition.rb
Overview
A surrogate’s ‘define` keyword results in one of these
Instance Attribute Summary collapse
-
#default_proc ⇒ Object
Returns the value of attribute default_proc.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #default(instance, invocation) ⇒ Object
- #has?(name) ⇒ Boolean
-
#initialize(name, options, default_proc) ⇒ MethodDefinition
constructor
A new instance of MethodDefinition.
- #must_match!(args) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(name, options, default_proc) ⇒ MethodDefinition
Returns a new instance of MethodDefinition.
9 10 11 |
# File 'lib/surrogate/method_definition.rb', line 9 def initialize(name, , default_proc) self.name, self., self.default_proc = name, , default_proc end |
Instance Attribute Details
#default_proc ⇒ Object
Returns the value of attribute default_proc
7 8 9 |
# File 'lib/surrogate/method_definition.rb', line 7 def default_proc @default_proc end |
#name ⇒ Object
Returns the value of attribute name
7 8 9 |
# File 'lib/surrogate/method_definition.rb', line 7 def name @name end |
#options ⇒ Object
Returns the value of attribute options
7 8 9 |
# File 'lib/surrogate/method_definition.rb', line 7 def @options end |
Instance Method Details
#[](key) ⇒ Object
17 18 19 |
# File 'lib/surrogate/method_definition.rb', line 17 def [](key) [key] end |
#default(instance, invocation) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/surrogate/method_definition.rb', line 29 def default(instance, invocation) if .has_key? :default [:default] elsif default_proc default_proc_as_method_on(instance).call(*invocation.args, &invocation.block) else raise "You should never get here. Please open a issue at http://github.com/JoshCheek/surrogate" end end |
#has?(name) ⇒ Boolean
13 14 15 |
# File 'lib/surrogate/method_definition.rb', line 13 def has?(name) .has_key? name end |
#must_match!(args) ⇒ Object
25 26 27 |
# File 'lib/surrogate/method_definition.rb', line 25 def must_match!(args) default_proc && errorizer.match!(*args) end |
#to_hash ⇒ Object
21 22 23 |
# File 'lib/surrogate/method_definition.rb', line 21 def to_hash end |