module EG

EG object creation functionality

Constants

RE_ATTR
RE_CONST
VERSION

Public Class Methods

call(hash) click to toggle source

Creates an object from its prototype hash @param hash [Hash] prototype hash @return [Module] created object

# File lib/eg.rb, line 15
def self.call(hash)
  Module.new.tap do |m|
    s = m.singleton_class
    hash.each do |k, v|
      if k =~ RE_CONST
        m.const_set(k, v)
      elsif k =~ RE_ATTR
        m.instance_variable_set(k, v)
      elsif v.respond_to?(:to_proc)
        s.define_method(k) { |*args| instance_exec(*args, &v) }
      else
        s.define_method(k) { v }
      end
    end
  end
end
to_proc() click to toggle source
# File lib/eg.rb, line 32
def self.to_proc
  ->(hash) { EG.call(hash) }
end