Sha256: 14d5828cd9e8bc14ca365ef7462a5ff85fc23e22780feaebe5bc01c6faa5b4ee

Contents?: true

Size: 1.39 KB

Versions: 6

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

module RaaP
  module BindCall
    class << self
      def define_method(...) = ::Module.instance_method(:define_method).bind_call(...)
      def respond_to?(...) = ::Kernel.instance_method(:respond_to?).bind_call(...)
      def instance_of?(...) = ::Kernel.instance_method(:instance_of?).bind_call(...)
      def is_a?(...) = ::Kernel.instance_method(:is_a?).bind_call(...)
      def extend(...) = ::Kernel.instance_method(:extend).bind_call(...)
      def name(...) = ::Module.instance_method(:name).bind_call(...)
      def to_s(...) = ::Kernel.instance_method(:to_s).bind_call(...)
      def public_send(...) = ::Kernel.instance_method(:public_send).bind_call(...)

      def class(obj)
        if instance_of?(obj, BasicObject)
          ::Kernel.instance_method(:class).bind_call(obj)
        else
          obj.class
        end
      end

      def inspect(obj)
        if instance_of?(obj, BasicObject)
          ::Kernel.instance_method(:inspect).bind_call(obj)
        else
          case obj
          when Hash
            body = obj.map do |k, v|
              "#{inspect(k)} => #{inspect(v)}"
            end
            "{#{body.join(', ')}}"
          when Array
            "[#{obj.map { |o| inspect(o) }.join(', ')}]"
          else
            obj.inspect
          end
        end
      rescue NoMethodError
        "#<#{self.class(obj)}>"
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
raap-1.0.0 lib/raap/bind_call.rb
raap-0.10.0 lib/raap/bind_call.rb
raap-0.9.0 lib/raap/bind_call.rb
raap-0.8.0 lib/raap/bind_call.rb
raap-0.6.0 lib/raap/bind_call.rb
raap-0.5.0 lib/raap/bind_call.rb