1
0
Fork 0
mirror of https://github.com/awesome-print/awesome_print synced 2023-03-27 23:22:34 -04:00

Fix unbound methods

This commit is contained in:
James Cox 2019-01-22 16:11:07 -05:00
parent f0ed2e219a
commit 7f7c0bf370
3 changed files with 20 additions and 7 deletions

View file

@ -11,8 +11,7 @@ module AwesomePrint
end
def self.formattable?(object)
puts "formattable? for METHOD..."
true
object.is_a?(Method)
end
def format(method)

View file

@ -0,0 +1,15 @@
require_relative 'method_formatter'
module AwesomePrint
module Formatters
class UnboundMethodFormatter < MethodFormatter
formatter_for :unboundmethod
def self.formattable?(object)
object.is_a?(UnboundMethod)
end
end
end
end

View file

@ -62,7 +62,9 @@ RSpec.describe 'Single method' do
method = ''.method(:is_a?)
expect(method.ai).to eq("\e[1;33mString (Kernel)\e[0m#\e[0;35mis_a?\e[0m\e[0;37m(arg1)\e[0m")
end
end
RSpec.describe 'unbound methods' do
it 'plain: should handle an unbound method' do
class Hello
def world; end
@ -76,11 +78,8 @@ RSpec.describe 'Single method' do
def world(a, b); end
end
method = Hello.instance_method(:world)
if RUBY_VERSION < '1.9.2'
expect(method.ai).to eq("\e[1;33mHello (unbound)\e[0m#\e[0;35mworld\e[0m\e[0;37m(arg1, arg2)\e[0m")
else
expect(method.ai).to eq("\e[1;33mHello (unbound)\e[0m#\e[0;35mworld\e[0m\e[0;37m(a, b)\e[0m")
end
puts "\e[1;33mHello (unbound)\e[0m#\e[0;35mworld\e[0m\e[0;37m(a, b)\e[0m"
expect(method.ai).to eq("\e[1;33mHello (unbound)\e[0m#\e[0;35mworld\e[0m\e[0;37m(a, b)\e[0m")
end
end