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-1.6 test/eg.rb
polyphony-1.5 test/eg.rb
polyphony-1.4 test/eg.rb
polyphony-1.3 test/eg.rb
polyphony-1.2.1 test/eg.rb
polyphony-1.2 test/eg.rb
polyphony-1.1.1 test/eg.rb
polyphony-1.1 test/eg.rb
polyphony-1.0.2 test/eg.rb
polyphony-1.0.1 test/eg.rb
polyphony-1.0 test/eg.rb
polyphony-0.99.6 test/eg.rb
polyphony-0.99.5 test/eg.rb
polyphony-0.99.4 test/eg.rb
polyphony-0.99.3 test/eg.rb
polyphony-0.99.2 test/eg.rb
polyphony-0.99.1 test/eg.rb
polyphony-0.99 test/eg.rb
polyphony-0.98 test/eg.rb
polyphony-0.97 test/eg.rb