Class Prototype
In: lib/more/facets/prototype.rb
Parent: Object

Methods

fn   meta   method_missing   new   new   trait   traits  

Public Class methods

New prototype object.

[Source]

# File lib/more/facets/prototype.rb, line 16
  def initialize(&block)
    @traits = []

    instance_eval(&block)

    h = {}
    iv = instance_variables
    iv.each { |k| h[k[1..-1].to_sym] = instance_eval{ instance_variable_get(k) } }
    meta.class_eval do
      h.each do |k,v|
        case v
        when Proc
          #define_method(k){ |*args| v[*args] }
          attr_reader k
        else
          attr_accessor k
        end
      end
    end
  end

Public Instance methods

[Source]

# File lib/more/facets/prototype.rb, line 37
  def fn(&blk)
    proc(&blk)
  end

[Source]

# File lib/more/facets/prototype.rb, line 46
  def meta
   (class << self; self; end)
  end

[Source]

# File lib/more/facets/prototype.rb, line 58
  def method_missing(s, *a, &b)
    if trait = traits.find{ |t| t.method_defined?(s) }
      trait.send(s,*a,&b)
    else
      super
    end
  end

[Source]

# File lib/more/facets/prototype.rb, line 41
  def new(o=nil)
    return o.clone if o
    return clone
  end

[Source]

# File lib/more/facets/prototype.rb, line 54
  def trait(obj)
    traits << obj.new
  end

[Source]

# File lib/more/facets/prototype.rb, line 50
  def traits
    @traits
  end

[Validate]