Sha256: 5608c5ecb6d7c924e7716df12eec48fd5e4f38d95044bb1c919d82e015ceb325

Contents?: true

Size: 1.05 KB

Versions: 9

Compression:

Stored size: 1.05 KB

Contents

module Pervasives
  VERSION = "1.1.0"
  def self.version() VERSION end

  Methods = Hash.new{|h,k| h[k] = {}}

  [Class, Module, Object].each do |type|
    type.instance_methods.each do |m|
      Methods[type]["#{ m }"] = type.instance_method m
    end
  end

  def self.call o, m, *a, &b
    list = 
      case o
        when Class then [Class, Module, Object]
        when Module then [Module, Object]
        when Object then [Object]
      end
    type = list.detect{|type| Methods[type]["#{ m }"]} 
    m = Methods[type]["#{ m }"]
    ( m ).bind( o ).call( *a, &b )
  end

  class ::Object
    def __pervasive__ m, *a, &b
      Pervasives.call self, m, *a, &b
    end
  end

  class Proxy
    instance_methods.each{|m| undef_method m unless m[%r/__/]}

    def initialize obj
      @obj = obj
    end

    def method_missing m, *a, &b
      Pervasives.call @obj, m, *a, &b
    end
  end

  def self.new *a, &b
    Proxy.new *a, &b
  end

  class ::Object
    def Pervasives *a, &b
      Proxy.new *a, &b
    end
  end
end

Version data entries

9 entries across 8 versions & 2 rubygems

Version Path
main-2.3.0 lib/main/pervasives.rb
main-2.2.0 lib/main/pervasives.rb
main-2.1.0 lib/main/pervasives.rb
main-2.0.0 lib/main/pervasives.rb
main-2.4.0 lib/main/pervasives.rb
main-2.6.0 lib/main/pervasives.rb
main-2.5.0 lib/main/pervasives.rb
pervasives-1.1.0 lib/pervasives.rb
pervasives-1.1.0 lib/pervasives-1.1.0.rb