Sha256: 0295d7aa9b7f82f06f435ee6a3382fc9b0a4accfef57ac11b2fa0481a5e9daca
Contents?: true
Size: 1.74 KB
Versions: 3
Compression:
Stored size: 1.74 KB
Contents
module Woyo module Evaluate def evaluate &block (block.arity < 1 ? (instance_eval &block) : block.call(self)) if block_given? self end module ClassMethods def children *childs @children ||= [] return @children if childs.empty? childs.each { |child| @children << child unless @children.include? child } @children.each do |child| class_eval(" def #{child}s ( @children ||= {} )[:#{child}] ||= ( @#{child}s ||= {} ) end def #{child} child_or_id, &block #{child} = child_or_id.kind_of?( #{child.capitalize} ) ? child_or_id : nil id = #{child} ? #{child}.id : child_or_id known = self.#{child}s[id] ? true : false case when #{child} && known && block_given? then #{child}.evaluate &block when #{child} && known && !block_given? then #{child} when #{child} && !known && block_given? then self.#{child}s[id] = #{child}.evaluate &block when #{child} && !known && !block_given? then self.#{child}s[id] = #{child} when !#{child} && known && block_given? then #{child} = self.#{child}s[id].evaluate &block when !#{child} && known && !block_given? then #{child} = self.#{child}s[id] when !#{child} && !known && block_given? then #{child} = self.#{child}s[id] = #{child.capitalize}.new id, context: self, &block when !#{child} && !known && !block_given? then #{child} = self.#{child}s[id] = #{child.capitalize}.new id, context: self end #{child} end ") end end end def self.included(base) base.extend(ClassMethods) end def children @children ||= {} end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
woyo-world-0.0.9 | lib/woyo/world/evaluate.rb |
woyo-world-0.0.8 | lib/woyo/world/evaluate.rb |
woyo-world-0.0.7 | lib/woyo/world/evaluate.rb |