Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/developwithpassion_arrays/object_extensions.rb
Instance Method Summary collapse
- #array(name) {|dsl| ... } ⇒ Object
- #initialize_arrays(*items) ⇒ Object
- #initialize_defaults(factory, *items) ⇒ Object
- #initialize_false(*items) ⇒ Object
- #initialize_hashes(*items) ⇒ Object
Instance Method Details
#array(name) {|dsl| ... } ⇒ Object
20 21 22 23 24 25 |
# File 'lib/developwithpassion_arrays/object_extensions.rb', line 20 def array(name,&block) initialize_arrays(name) dsl = DevelopWithPassion::Arrays::Dsl.new(name) yield dsl if block_given? DevelopWithPassion::Arrays::ModuleRegistry.all_modules.each{|module_factory| self.extend(module_factory.run_using(dsl))} end |
#initialize_arrays(*items) ⇒ Object
8 9 10 |
# File 'lib/developwithpassion_arrays/object_extensions.rb', line 8 def initialize_arrays(*items) initialize_defaults(lambda{[]},*items) end |
#initialize_defaults(factory, *items) ⇒ Object
2 3 4 5 6 |
# File 'lib/developwithpassion_arrays/object_extensions.rb', line 2 def initialize_defaults(factory,*items) items.each do|item| instance_variable_set("@#{item}",factory.call) end end |
#initialize_false(*items) ⇒ Object
16 17 18 |
# File 'lib/developwithpassion_arrays/object_extensions.rb', line 16 def initialize_false(*items) initialize_defaults(lambda{false},*items) end |
#initialize_hashes(*items) ⇒ Object
12 13 14 |
# File 'lib/developwithpassion_arrays/object_extensions.rb', line 12 def initialize_hashes(*items) initialize_defaults(lambda{{}},*items) end |