Struct#inspect needs more meaningful output
|Target version:||next minor|
When inheriting directly from Struct.new, Class#ancestors shows a meaningless anonymous Class:
class Point < Struct.new(:x, :y) def distance ((x ** 2) + (y ** 2)) ** 0.5 end end Point.ancestors # => [Point, #<Class:0x007fe204a1a228>, Struct, Enumerable, Object, Kernel, BasicObject]
Perhaps, the anonymous Class could list the Struct's fields?
#6 Updated by Yusuke Endoh over 1 year ago
This is not a bug. This ticket has been moved to the feature tracker.
I'm not against this proposal, but I don't think that people normally check the singleton class to know Struct fields. You may want to use Struct.#members:
p Point.members #=> [:x, :y]
It is shorter than ancestors.
Yusuke Endoh email@example.com