Sha256: 038fc854161a04380d09d92b8a539ebe8841adeb68b746ab8da05c88f95f07c1

Contents?: true

Size: 1003 Bytes

Versions: 5

Compression:

Stored size: 1003 Bytes

Contents

module PipeRpc
  class BasicInterface < BasicObject
    wanted_methods = [:initialize, :__id__, :object_id, :__send__, :respond_to?, :method_missing]

    existing_methods = if ::Object.const_defined?(:MRUBY_VERSION)
      [:initialize, :method_missing]
    else
      [:initialize, :__id__, :__send__, :instance_eval, :instance_exec, :method_missing,
        :singleton_method_added, :singleton_method_removed, :singleton_method_undefined]
    end

    # Remove unwanted methods
    unwanted_methods = existing_methods - wanted_methods
    unwanted_methods.each { |m| undef_method m }

    # Add non-existing methods by including sorted out Kernel module
    to_be_added_methods = wanted_methods - existing_methods
    kernel = ::Kernel.dup
    kernel.class_eval do
      (instance_methods - to_be_added_methods).each{ |m| remove_method m }
      private_instance_methods.each{ |m| remove_method m } if respond_to? :private_instance_methods
    end
    include kernel

    alias send __send__
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pipe_rpc-2.3.0 lib/pipe_rpc/basic_interface.rb
pipe_rpc-2.2.3 lib/pipe_rpc/basic_interface.rb
pipe_rpc-2.2.2 lib/pipe_rpc/basic_interface.rb
pipe_rpc-2.2.1 lib/pipe_rpc/basic_interface.rb
pipe_rpc-2.2.0 lib/pipe_rpc/basic_interface.rb