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.43.2 test/eg.rb
polyphony-0.43.1 test/eg.rb
polyphony-0.43 test/eg.rb
polyphony-http-0.28 test/eg.rb
polyphony-0.42 test/eg.rb
polyphony-0.41 test/eg.rb
polyphony-0.40 test/eg.rb
polyphony-0.39 test/eg.rb
polyphony-http-0.27 test/eg.rb
polyphony-0.38 test/eg.rb
polyphony-0.36 test/eg.rb
polyphony-0.34 test/eg.rb
polyphony-0.33 test/eg.rb
polyphony-http-0.26 test/eg.rb
polyphony-0.32 test/eg.rb
polyphony-0.31 test/eg.rb
polyphony-http-0.25 test/eg.rb
polyphony-http-0.24 test/eg.rb
polyphony-0.30 test/eg.rb
polyphony-0.29 test/eg.rb