Issue #7349 has been reported by postmodern (Hal Brodigan). ---------------------------------------- Bug #7349: Struct#inspect needs more meaningful output https://bugs.ruby-lang.org/issues/7349 Author: postmodern (Hal Brodigan) Status: Open Priority: Low Assignee: Category: core Target version: next minor ruby -v: ruby 2.0.0dev (2012-11-01 trunk 37411) [x86_64-linux] 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>
on 2012-11-14 03:32
on 2012-11-14 04:10
Issue #7349 has been updated by shyouhei (Shyouhei Urabe). Sounds nice to me. +1 ---------------------------------------- Bug #7349: Struct#inspect needs more meaningful output https://bugs.ruby-lang.org/issues/7349#change-32890 Author: postmodern (Hal Brodigan) Status: Open Priority: Low Assignee: Category: core Target version: next minor ruby -v: ruby 2.0.0dev (2012-11-01 trunk 37411) [x86_64-linux] 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>
on 2012-11-14 06:44
I like it too. Could even be:
Point.ancestors
# => [Point, Struct.new(:x, :y), Struct, Enumerable, Object, Kernel,
BasicObject]
on 2012-11-16 00:20
Issue #7349 has been updated by Eregon (Benoit Daloze).
It might be worth pointing out that this should not happen if the Struct
generated class is assigned to a constant (and so one level of
inheritance is not unused):
Point = Struct.new(:x, :y) do
def distance
Math.hypot(x,y)
end
end
----------------------------------------
Bug #7349: Struct#inspect needs more meaningful output
https://bugs.ruby-lang.org/issues/7349#change-32944
Author: postmodern (Hal Brodigan)
Status: Open
Priority: Low
Assignee:
Category: core
Target version: next minor
ruby -v: ruby 2.0.0dev (2012-11-01 trunk 37411) [x86_64-linux]
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>
on 2012-11-25 02:45
Issue #7349 has been updated by mame (Yusuke Endoh). Status changed from Open to Assigned Assignee set to matz (Yukihiro Matsumoto) ---------------------------------------- Feature #7349: Struct#inspect needs more meaningful output https://bugs.ruby-lang.org/issues/7349#change-33837 Author: postmodern (Hal Brodigan) Status: Assigned Priority: Low Assignee: matz (Yukihiro Matsumoto) Category: core 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? #<Class:x, y>
on 2012-11-25 02:51
Issue #7349 has been updated by mame (Yusuke Endoh). 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 <mame@tsg.ne.jp> ---------------------------------------- Feature #7349: Struct#inspect needs more meaningful output https://bugs.ruby-lang.org/issues/7349#change-33838 Author: postmodern (Hal Brodigan) Status: Assigned Priority: Low Assignee: matz (Yukihiro Matsumoto) Category: core 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? #<Class:x, y>
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.