lib/raap/bind_call.rb in raap-0.3.0 vs lib/raap/bind_call.rb in raap-0.4.0
- old
+ new
@@ -9,22 +9,34 @@
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 respond_to?(obj, :class)
- obj.class
- else
+ if instance_of?(obj, BasicObject)
::Kernel.instance_method(:class).bind_call(obj)
+ else
+ obj.class
end
end
def inspect(obj)
- if respond_to?(obj, :inspect)
- obj.inspect
- else
+ 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