Class: Sinclair
- Extended by:
- ClassMethods
- Includes:
- OptionsParser
- Defined in:
- lib/sinclair.rb,
lib/sinclair/model.rb,
lib/sinclair/caster.rb,
lib/sinclair/config.rb,
lib/sinclair/options.rb,
lib/sinclair/version.rb,
lib/sinclair/matchers.rb,
lib/sinclair/settable.rb,
lib/sinclair/exception.rb,
lib/sinclair/comparable.rb,
lib/sinclair/input_hash.rb,
lib/sinclair/config_class.rb,
lib/sinclair/configurable.rb,
lib/sinclair/env_settable.rb,
lib/sinclair/class_methods.rb,
lib/sinclair/matchers/base.rb,
lib/sinclair/model/builder.rb,
lib/sinclair/chain_settable.rb,
lib/sinclair/config_builder.rb,
lib/sinclair/config_factory.rb,
lib/sinclair/equals_checker.rb,
lib/sinclair/method_builder.rb,
lib/sinclair/options_parser.rb,
lib/sinclair/options/builder.rb,
lib/sinclair/settable/caster.rb,
lib/sinclair/settable/builder.rb,
lib/sinclair/method_definition.rb,
lib/sinclair/matchers/method_to.rb,
lib/sinclair/method_definitions.rb,
lib/sinclair/matchers/add_method.rb,
lib/sinclair/method_builder/base.rb,
lib/sinclair/caster/class_methods.rb,
lib/sinclair/equals_checker/reader.rb,
lib/sinclair/model/builder_options.rb,
lib/sinclair/options/class_methods.rb,
lib/sinclair/config/methods_builder.rb,
lib/sinclair/matchers/add_method_to.rb,
lib/sinclair/settable/class_methods.rb,
lib/sinclair/comparable/class_methods.rb,
lib/sinclair/matchers/add_class_method.rb,
lib/sinclair/matchers/change_method_on.rb,
lib/sinclair/matchers/add_class_method_to.rb,
lib/sinclair/matchers/add_instance_method.rb,
lib/sinclair/matchers/change_class_method.rb,
lib/sinclair/method_definition/stringifier.rb,
lib/sinclair/method_definition/block_helper.rb,
lib/sinclair/matchers/add_instance_method_to.rb,
lib/sinclair/matchers/change_class_method_on.rb,
lib/sinclair/matchers/change_instance_method.rb,
lib/sinclair/method_definition/call_definition.rb,
lib/sinclair/matchers/change_instance_method_on.rb,
lib/sinclair/method_builder/call_method_builder.rb,
lib/sinclair/method_definition/block_definition.rb,
lib/sinclair/method_definition/parameter_helper.rb,
lib/sinclair/method_builder/block_method_builder.rb,
lib/sinclair/method_definition/parameter_builder.rb,
lib/sinclair/method_definition/string_definition.rb,
lib/sinclair/method_builder/string_method_builder.rb
Overview
Builder that add instance methods to a class
Direct Known Subclasses
Config::MethodsBuilder, Model::Builder, Options::Builder, Settable::Builder
Defined Under Namespace
Modules: ChainSettable, ClassMethods, Comparable, ConfigClass, Configurable, EnvSettable, Matchers, OptionsParser, Settable Classes: Caster, Config, ConfigBuilder, ConfigFactory, EqualsChecker, Exception, InputHash, MethodBuilder, MethodDefinition, MethodDefinitions, Model, Options
Constant Summary collapse
- VERSION =
'2.1.1'
Instance Attribute Summary collapse
-
#klass ⇒ Class
readonly
private
Class that will receive the methods.
Attributes included from OptionsParser
Class Method Summary collapse
-
.build(klass, options = {}, &block) { ... } ⇒ Array<MethodDefinition>
Runs build using a block for adding the methods.
Instance Method Summary collapse
-
#add_class_method(*args, type: nil, **options, &block) ⇒ Array<MethodDefinition>
Add a method to the method list to be created on klass.
-
#add_method(*args, type: nil, **options, &block) ⇒ Array<MethodDefinition>
Add a method to the method list to be created on klass instances.
-
#build ⇒ Array<MethodDefinition>
builds all the methods added into the klass.
-
#eval_and_add_method(name, &block) ⇒ Array<MethodDefinition>
Evaluetes a block which will result in a String, the method code.
-
#initialize(klass, options = {}) ⇒ Sinclair
constructor
Returns a new instance of Sinclair.
Methods included from OptionsParser
Constructor Details
#initialize(klass, options = {}) ⇒ Sinclair
Returns a new instance of Sinclair
173 174 175 176 |
# File 'lib/sinclair.rb', line 173 def initialize(klass, = {}) @klass = klass @options = end |
Instance Attribute Details
#klass ⇒ Class (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.
Class that will receive the methods
469 470 471 |
# File 'lib/sinclair.rb', line 469 def klass @klass end |
Class Method Details
.build(klass, options = {}, &block) { ... } ⇒ Array<MethodDefinition>
Runs build using a block for adding the methods
The block is executed adding the methods and after the builder runs build building all the methods
|
# File 'lib/sinclair.rb', line 109
|
Instance Method Details
#add_class_method(name, code, **options) ⇒ Array<MethodDefinition> #add_class_method(name, **options, &block) ⇒ Array<MethodDefinition> #add_class_method(*args, type: **options, &block) ⇒ Array<MethodDefinition>
Add a method to the method list to be created on klass
382 383 384 |
# File 'lib/sinclair.rb', line 382 def add_class_method(*args, type: nil, **, &block) class_definitions.add(*args, type: type, **, &block) end |
#add_method(name, code, **options) ⇒ Array<MethodDefinition> #add_method(name, **options, &block) ⇒ Array<MethodDefinition> #add_method(*args, type: , **options, &block) ⇒ Array<MethodDefinition>
Add a method to the method list to be created on klass instances
297 298 299 |
# File 'lib/sinclair.rb', line 297 def add_method(*args, type: nil, **, &block) definitions.add(*args, type: type, **, &block) end |
#build ⇒ Array<MethodDefinition>
builds all the methods added into the klass
196 197 198 199 |
# File 'lib/sinclair.rb', line 196 def build builder.build_methods(definitions, MethodBuilder::INSTANCE_METHOD) builder.build_methods(class_definitions, MethodBuilder::CLASS_METHOD) end |
#eval_and_add_method(name, &block) ⇒ Array<MethodDefinition>
Evaluetes a block which will result in a String, the method code
456 457 458 |
# File 'lib/sinclair.rb', line 456 def eval_and_add_method(name, &block) add_method(name, instance_eval(&block)) end |