Actions
Feature #17210
closedMore readable and useful `Set#inspect`
Feature #17210:
More readable and useful `Set#inspect`
Actions
Added by marcandre (Marc-Andre Lafortune) almost 6 years ago. Updated 8 months ago.
BTW, as a side note, it would be good to have some "style guide" for inspect behavior in Ruby. Ad-hoc rule seem to be #<ClassName some representation of content> most of the time, except for objects that have corresponding literals -- they are just represented by literals. But:
#<struct A a=1, b=2>, #<Date: 2020-10-02 ((2459125j,0s,0n),+0s,2299161j)>, #<Set: {1, 2, 3}>, #<OpenStruct a=1, b=2>, #<Enumerator: [1, 2, 3]:map>, <File:README.md>, #<CSV::Row "Name":"Bob" "Department":"Engineering" "Salary":"1000">Time is breaking all conventions being represented as 2020-10-02 12:10:51 +0300 -- which even doesn't look as one atomic entitymatrix does similar to proposed: Matrix[[25, 93], [-1, 66]], Vector[1, 2], so it is a bit unusual for #inspect, though it is not necessary a bad thng+1
I second the proposal.
p [1, 2, 3] #=> [1, 2, 3]
p "hello" #=> "hello"
p 1.0 #=> 1.0
p({"x"=>1}) #=> {"x"=>1}
p 1..2 #=> 1..2
p nil #=> nil
p true #=> true
p :name #=> :name
p Array #=> Array
require "matrix"
p Matrix[[1, 2], [3, 4]] #=> Matrix[[1, 2], [3, 4]]
p Vector[1, 2] #=> Vector[1, 2]
The output of the major classes equal to Ruby code(literal or syntax sugar).
It is very useful and readable.