Module: ObjectLoader::ClassMethods
- Defined in:
- lib/object_loader/class_methods.rb
Instance Method Summary collapse
-
#load_object(path, *arguments) ⇒ Object
Loads a compatible object.
-
#load_object_block(path) ⇒ Proc
Loads a block for the Class.
-
#object(*args) { ... } ⇒ Object
Creates a loadable object using the arguments and block.
Instance Method Details
#load_object(path, *arguments) ⇒ Object
Loads a compatible object.
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/object_loader/class_methods.rb', line 32 def load_object(path,*arguments) pending = ObjectLoader.load_blocks(path) pending_class, pending_block = pending.find do |klass,block| klass.ancestors.include?(self) end if (pending_class && pending_block) obj = pending_class.new(*arguments) obj.instance_eval(&pending_block) obj end end |
#load_object_block(path) ⇒ Proc
Loads a block for the Class.
14 15 16 |
# File 'lib/object_loader/class_methods.rb', line 14 def load_object_block(path) ObjectLoader.load_blocks(path)[self] end |
#object(*args) { ... } ⇒ Object
Creates a loadable object using the arguments and block.
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/object_loader/class_methods.rb', line 58 def object(*args,&block) if (args.empty? && ObjectLoader.is_pending?) ObjectLoader.pending[self] = block return nil else new_object = self.new(*args) new_object.instance_eval(&block) if block return new_object end end |