Class: Sinclair
- Inherits:
-
Object
- Object
- Sinclair
- Includes:
- OptionsParser
- Defined in:
- lib/sinclair.rb,
lib/sinclair/config.rb,
lib/sinclair/version.rb,
lib/sinclair/matchers.rb,
lib/sinclair/config_class.rb,
lib/sinclair/configurable.rb,
lib/sinclair/env_settable.rb,
lib/sinclair/config_builder.rb,
lib/sinclair/config_factory.rb,
lib/sinclair/method_builder.rb,
lib/sinclair/options_parser.rb,
lib/sinclair/method_definition.rb,
lib/sinclair/method_definitions.rb,
lib/sinclair/matchers/add_method.rb,
lib/sinclair/method_builder/base.rb,
lib/sinclair/env_settable/builder.rb,
lib/sinclair/config/methods_builder.rb,
lib/sinclair/matchers/add_method_to.rb,
lib/sinclair/matchers/add_class_method.rb,
lib/sinclair/matchers/add_class_method_to.rb,
lib/sinclair/matchers/add_instance_method.rb,
lib/sinclair/method_definition/block_helper.rb,
lib/sinclair/matchers/add_instance_method_to.rb,
lib/sinclair/method_definition/block_definition.rb,
lib/sinclair/method_builder/block_method_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
Defined Under Namespace
Modules: ConfigClass, Configurable, EnvSettable, Matchers, OptionsParser Classes: Config, ConfigBuilder, ConfigFactory, MethodBuilder, MethodDefinition, MethodDefinitions
Constant Summary collapse
- VERSION =
'1.5.1'
Instance Attribute Summary
Attributes included from OptionsParser
Instance Method Summary collapse
-
#add_class_method(name, code = nil, **options, &block) ⇒ Array<MethodDefinition>
Add a method to the method list to be created on klass.
-
#add_method(name, code = 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
148 149 150 151 |
# File 'lib/sinclair.rb', line 148 def initialize(klass, = {}) @klass = klass @options = end |
Instance Method Details
#add_class_method(name, code, **options) ⇒ Array<MethodDefinition> #add_class_method(name, **options, &block) ⇒ Array<MethodDefinition>
Add a method to the method list to be created on klass
268 269 270 271 272 |
# File 'lib/sinclair.rb', line 268 def add_class_method(name, code = nil, **, &block) class_definitions.add( name, code, **, &block ) end |
#add_method(name, code, **options) ⇒ Array<MethodDefinition> #add_method(name, **options, &block) ⇒ Array<MethodDefinition>
Add a method to the method list to be created on klass instances
222 223 224 225 226 |
# File 'lib/sinclair.rb', line 222 def add_method(name, code = nil, **, &block) definitions.add( name, code, **, &block ) end |
#build ⇒ Array<MethodDefinition>
builds all the methods added into the klass
171 172 173 174 |
# File 'lib/sinclair.rb', line 171 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
344 345 346 |
# File 'lib/sinclair.rb', line 344 def eval_and_add_method(name, &block) add_method(name, instance_eval(&block)) end |