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/config_builder.rb,
lib/sinclair/config_factory.rb,
lib/sinclair/options_parser.rb,
lib/sinclair/method_definition.rb,
lib/sinclair/method_definitions.rb,
lib/sinclair/matchers/add_method.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/matchers/add_instance_method_to.rb,
lib/sinclair/method_definition/block_definition.rb,
lib/sinclair/method_definition/string_definition.rb,
lib/sinclair/method_definition/class_block_definition.rb,
lib/sinclair/method_definition/class_method_definition.rb,
lib/sinclair/method_definition/class_string_definition.rb,
lib/sinclair/method_definition/instance_block_definition.rb,
lib/sinclair/method_definition/instance_method_definition.rb,
lib/sinclair/method_definition/instance_string_definition.rb
Overview
Builder that add instance methods to a class
Direct Known Subclasses
Defined Under Namespace
Modules: ConfigClass, Configurable, Matchers, OptionsParser Classes: Config, ConfigBuilder, ConfigFactory, MethodDefinition, MethodDefinitions
Constant Summary collapse
- VERSION =
'1.4.2'
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
146 147 148 149 |
# File 'lib/sinclair.rb', line 146 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 273 |
# File 'lib/sinclair.rb', line 268 def add_class_method(name, code = nil, **, &block) definitions.add( MethodDefinition::ClassMethodDefinition, 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
221 222 223 224 225 226 |
# File 'lib/sinclair.rb', line 221 def add_method(name, code = nil, **, &block) definitions.add( MethodDefinition::InstanceMethodDefinition, name, code, **, &block ) end |
#build ⇒ Array<MethodDefinition>
builds all the methods added into the klass
169 170 171 172 173 |
# File 'lib/sinclair.rb', line 169 def build definitions.each do |definition| definition.build(klass) end end |
#eval_and_add_method(name, &block) ⇒ Array<MethodDefinition>
Evaluetes a block which will result in a String, the method code
345 346 347 |
# File 'lib/sinclair.rb', line 345 def eval_and_add_method(name, &block) add_method(name, instance_eval(&block)) end |