Class: FrenchMan::Blueprint
- Inherits:
-
Object
- Object
- FrenchMan::Blueprint
- Defined in:
- lib/french_man.rb
Overview
The blueprint to create hashes from
Instance Method Summary collapse
-
#initialize(&block) ⇒ Blueprint
constructor
:nodoc:.
-
#merge(plan) ⇒ Object
takes a hash as an argument and merges it with a the blueprint hash and returns the hash wrapped in an
ObjectifiedHash
object. -
#method_missing(attribute, &block) ⇒ Object
:nodoc:.
Constructor Details
#initialize(&block) ⇒ Blueprint
:nodoc:
80 81 82 83 |
# File 'lib/french_man.rb', line 80 def initialize(&block) #:nodoc: @hash = {} instance_eval &block end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(attribute, &block) ⇒ Object
:nodoc:
96 97 98 |
# File 'lib/french_man.rb', line 96 def method_missing(attribute, &block) #:nodoc: @hash.merge!(attribute => block) end |
Instance Method Details
#merge(plan) ⇒ Object
takes a hash as an argument and merges it with a the blueprint hash and returns the hash wrapped in an ObjectifiedHash
object
87 88 89 90 91 92 93 94 |
# File 'lib/french_man.rb', line 87 def merge(plan) attribute_names = @hash.keys - plan.keys attribute_names.each do |attribute_name| value = @hash[attribute_name] plan[attribute_name] = value.respond_to?(:call) ? value.call : value end ObjectifiedHash.new plan end |