Sha256: 878e9bdb415531ba699d93d376786db0a46c80f1781f1052133c6d4de5f7a838

Contents?: true

Size: 828 Bytes

Versions: 1

Compression:

Stored size: 828 Bytes

Contents

module Redef
  Redef::VERSION = '0.4.2'
  def Redef.version() Redef::VERSION end
end

class Class
private
  def redefined
    singleton_class =
      class << self
        self
      end
    hash = Hash.new
    singleton_class.module_eval{ define_method(:redefined){ hash } }
    redefined
  end

  def redefining &block
    include( redefined[:Module] ||= Module.new )

    m = Module.new(&block)

    methods = m.instance_methods(false) & instance_methods(false)

    methods.each do |method|
      redefined[method] = instance_method method

      redefined[:Module].module_eval <<-redefintion
        def #{ method }(*a, &b)
          self.class.redefined['#{ method }'].bind(self).call(*a, &b)
        end
      redefintion

      remove_method method
    end

    include m
  end

  alias_method 'redef', 'redefining'
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
redef-0.4.2 lib/redef.rb