Module: ValueSemantics
- Defined in:
- lib/value_semantics.rb,
lib/value_semantics/version.rb
Defined Under Namespace
Modules: Anything, Bool, ClassMethods, InstanceMethods Classes: ArrayOf, Attribute, DSL, Either, Error, MissingAttributes, NoDefaultValue, Recipe, Struct, UnrecognizedAttributes
Constant Summary collapse
- NOT_SPECIFIED =
Object.new.freeze
- VERSION =
"3.2.1"
Class Method Summary collapse
-
.bake_module(recipe) ⇒ Module
Creates a module from a Recipe.
-
.for_attributes { ... } ⇒ Module
Creates a module via the DSL.
Class Method Details
.bake_module(recipe) ⇒ Module
Creates a module from a Recipe
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/value_semantics.rb', line 29 def self.bake_module(recipe) Module.new do const_set(:VALUE_SEMANTICS_RECIPE__, recipe) include(InstanceMethods) # define the attr readers recipe.attributes.each do |attr| module_eval("def #{attr.name}; #{attr.instance_variable}; end") end def self.included(base) base.const_set(:ValueSemantics_Attributes, self) base.extend(ClassMethods) end end end |
.for_attributes { ... } ⇒ Module
Creates a module via the DSL
18 19 20 21 |
# File 'lib/value_semantics.rb', line 18 def self.for_attributes(&block) recipe = DSL.run(&block) bake_module(recipe) end |