Я не могу заставить pry показать экземпляры моего класса, производные от Range, так как я переопределил to_s / inspect:
[1] pry(main)> class RangeInherited < Range
[1] pry(main)* def initialize(first, last, added=nil)
[1] pry(main)* super(first, last)
[1] pry(main)* @added = added
[1] pry(main)* end
[1] pry(main)* def to_s
[1] pry(main)* "#<".concat(self.class.name, " ", super, " ", @added || "-", ">")
[1] pry(main)* end
[1] pry(main)* alias inspect to_s
[1] pry(main)* end
=> nil
[2] pry(main)> r = RangeInherited.new(1, 10, "x")
=> 1..10
Несмотря на то, что прямые вызовы to_s / inspect дают желаемый результат:
[3] pry(main)> r.to_s
=> "#<RangeInherited 1..10 x>"
[4] pry(main)> r.inspect
=> "#<RangeInherited 1..10 x>"
[5] pry(main)>
Почему?
С помощью ответа Марцина Колодзея я пришел к следующему решению:
[1] pry(main)> class RangeInherited < Range
[1] pry(main)* def initialize(first, last, added=nil)
[1] pry(main)* super(first, last)
[1] pry(main)* @added = added
[1] pry(main)* end
[1] pry(main)* def to_s
[1] pry(main)* "#<".concat(self.class.name, " ", super, " ", @added || "-", ">")
[1] pry(main)* end
[1] pry(main)* alias inspect to_s
[1] pry(main)* def pretty_print(pp)
[1] pry(main)* pp.text(to_s)
[1] pry(main)* end
[1] pry(main)* end
=> :pretty_print
[2] pry(main)>
[3] pry(main)> r = RangeInherited.new(1, 10, "x")
=> #<RangeInherited 1..10 x>