Sha256: 56f6f108a309ecb6b334c4fead14b4b9bf53195bfffb3ac48135b3b7c57ccf3d

Contents?: true

Size: 601 Bytes

Versions: 129

Compression:

Stored size: 601 Bytes

Contents

# frozen_string_literal: true

module Kernel
  RE_CONST  = /^[A-Z]/.freeze
  RE_ATTR   = /^@(.+)$/.freeze

  def eg(hash)
    Module.new.tap do |m|
      s = m.singleton_class
      hash.each do |k, v|
        case k
        when RE_CONST
          m.const_set(k, v)
        when RE_ATTR
          m.instance_variable_set(k, v)
        else
          block = if v.respond_to?(:to_proc)
                    proc { |*args| instance_exec(*args, &v) }
                  else
                    proc { v }
                  end
          s.define_method(k, &block)
        end
      end
    end
  end
end

Version data entries

129 entries across 129 versions & 2 rubygems

Version Path
polyphony-0.28 test/eg.rb
polyphony-0.27 test/eg.rb
polyphony-0.26 test/eg.rb
polyphony-0.25 test/eg.rb
polyphony-0.24 test/eg.rb
polyphony-0.23 test/eg.rb
polyphony-0.22 test/eg.rb
polyphony-0.21 test/eg.rb
polyphony-0.20 test/eg.rb