Class: Sinclair::MethodDefinition Private
- Inherits:
-
Object
- Object
- Sinclair::MethodDefinition
- Includes:
- OptionsParser
- Defined in:
- lib/sinclair/method_definition.rb,
lib/sinclair/method_definition/block_helper.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
Modules: BlockHelper 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 collapse
-
#name ⇒ String, Symbol
readonly
private
name of the method.
Attributes included from OptionsParser
Class Method Summary collapse
-
.default_value(method_name, value) ⇒ Symbol
private
Builds a method that will return the same value always.
-
.from(name, code = nil, **options, &block) ⇒ Base
private
builds a method definition based on arguments.
Instance Method Summary collapse
-
#build(_klass) ⇒ Symbol
abstract
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.
59 60 61 62 |
# File 'lib/sinclair/method_definition.rb', line 59 def initialize(name, **) @name = name @options = DEFAULT_OPTIONS.merge() end |
Instance Attribute Details
#name ⇒ String, Symbol (readonly)
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.
name of the method
20 21 22 |
# File 'lib/sinclair/method_definition.rb', line 20 def name @name end |
Class Method Details
.default_value(method_name, value) ⇒ 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.
Builds a method that will return the same value always
30 31 32 |
# File 'lib/sinclair/method_definition.rb', line 30 def self.default_value(method_name, value) define_method(method_name) { value } end |
.from(name, code = nil, **options, &block) ⇒ Base
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.
builds a method definition based on arguments
when block is given, returns a BlockDefinition and returns a StringDefinition otherwise
47 48 49 50 51 52 53 |
# File 'lib/sinclair/method_definition.rb', line 47 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
76 77 78 79 |
# File 'lib/sinclair/method_definition.rb', line 76 def build(_klass) raise 'Build is implemented in subclasses. ' \ "Use #{self.class}.from to initialize a proper object" end |