Class: Sinclair::MethodDefinition Private
- Inherits:
-
Object
- Object
- Sinclair::MethodDefinition
- Includes:
- OptionsParser
- Defined in:
- lib/sinclair/method_definition.rb,
lib/sinclair/method_definition/block_definition.rb,
lib/sinclair/method_definition/string_definition.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Definition of the code or block to be aded as method
Direct Known Subclasses
Defined Under Namespace
Classes: BlockDefinition, StringDefinition
Constant Summary collapse
- DEFAULT_OPTIONS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Default options of initialization
{ cached: false }.freeze
Instance Attribute Summary
Attributes included from OptionsParser
Class Method Summary collapse
-
.from(name, code = nil, **options, &block) ⇒ MethodDefinition
private
Creates a new instance based on arguments.
Instance Method Summary collapse
-
#build(_klass) ⇒ Symbol
private
Adds the method to given klass.
-
#initialize(name, **options) ⇒ MethodDefinition
constructor
private
A new instance of MethodDefinition.
Methods included from OptionsParser
Constructor Details
#initialize(name, **options) ⇒ MethodDefinition
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of MethodDefinition.
36 37 38 39 |
# File 'lib/sinclair/method_definition.rb', line 36 def initialize(name, **) @name = name @options = DEFAULT_OPTIONS.merge() end |
Class Method Details
.from(name, code = nil, **options, &block) ⇒ MethodDefinition
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a new instance based on arguments
24 25 26 27 28 29 30 |
# File 'lib/sinclair/method_definition.rb', line 24 def self.from(name, code = nil, **, &block) if block BlockDefinition.new(name, **, &block) else StringDefinition.new(name, code, **) end end |
Instance Method Details
#build(_klass) ⇒ Symbol
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Adds the method to given klass
This should be implemented on child classes
91 92 93 94 |
# File 'lib/sinclair/method_definition.rb', line 91 def build(_klass) raise 'Build is implemented in subclasses. ' \ "Use #{self.class}.from to initialize a proper object" end |