Project

General

Profile

Actions

Feature #7349

open

Struct#inspect needs more meaningful output

Added by postmodern (Hal Brodigan) over 11 years ago. Updated over 6 years ago.

Status:
Assigned
Target version:
-
[ruby-core:49328]

Description

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?

#<Class:x, y>
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0