Sha256: f298488a569d6d4a69036e01ab14e8e80be1784925b704e0161b7dce9e705de4

Contents?: true

Size: 620 Bytes

Versions: 26

Compression:

Stored size: 620 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, &block| instance_exec { v.(*args, &block) } }
                  else
                    proc { v }
                  end
          s.define_method(k, &block)
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
tipi-0.55 test/eg.rb
tipi-0.54 test/eg.rb
tipi-0.53 test/eg.rb
tipi-0.52 test/eg.rb
tipi-0.51 test/eg.rb
tipi-0.50 test/eg.rb
tipi-0.49 test/eg.rb
tipi-0.47 test/eg.rb
tipi-0.46 test/eg.rb
tipi-0.45 test/eg.rb
tipi-0.43 test/eg.rb
tipi-0.42 test/eg.rb
tipi-0.41 test/eg.rb
tipi-0.40 test/eg.rb
tipi-0.39 test/eg.rb
tipi-0.38 test/eg.rb
tipi-0.37.2 test/eg.rb
tipi-0.37.1 test/eg.rb
tipi-0.37 test/eg.rb
tipi-0.36 test/eg.rb