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.47.3 test/eg.rb
polyphony-0.47.2 test/eg.rb
polyphony-0.47.1 test/eg.rb
polyphony-0.47.0 test/eg.rb
polyphony-0.46.1 test/eg.rb
polyphony-0.46.0 test/eg.rb
polyphony-0.45.5 test/eg.rb
polyphony-0.45.4 test/eg.rb
polyphony-0.45.2 test/eg.rb
polyphony-0.45.1 test/eg.rb
polyphony-0.45.0 test/eg.rb
polyphony-0.44.0 test/eg.rb
polyphony-0.43.11 test/eg.rb
polyphony-0.43.10 test/eg.rb
polyphony-0.43.9 test/eg.rb
polyphony-0.43.8 test/eg.rb
polyphony-0.43.6 test/eg.rb
polyphony-0.43.5 test/eg.rb
polyphony-0.43.4 test/eg.rb
polyphony-0.43.3 test/eg.rb