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