-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Socket::Address#pretty_print and #inspect #6704
Add Socket::Address#pretty_print and #inspect #6704
Conversation
Why? How does it look if you print an array of addresses? |
p [Socket::IPAddress.new("127.0.0.1", 80), Socket::IPAddress.new("::1", 8000)]
#before:
# => [Socket::IPAddress(@family=INET, @size=16, @port=80, @address="127.0.0.1", @addr6=nil, @addr4=LibC::InAddr(@s_addr=16777343_u32)), Socket::IPAddress(@family=INET6, @size=28, @port=8000, @address="::1", @addr6=LibC::In6Addr(@__in6_u=LibC::In6AddrIn6U(@__u6_addr8=StaticArray[0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 1_u8], @__u6_addr16=StaticArray[0_u16, 0_u16, 0_u16, 0_u16, 0_u16, 0_u16, 0_u16, 256_u16], @__u6_addr32=StaticArray[0_u32, 0_u32, 0_u32, 16777216_u32])), @addr4=nil)]
# after:
# => [127.0.0.1:80, [::1]:8000] I don't think there is any reason for |
I agree. It should print something like |
Not sure Ruby has a class for ip addresses, but it would be interesting to see what Ruby does here. |
Here's Ruby:
As I mentioned in some other PR, |
There is IPAddr but it's quite a bit different from Crystal's p IPAddr.new "3ffe:505:2::1" # => #<IPAddr: IPv6:3ffe:0505:0002:0000:0000:0000:0000:0001/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff> |
You're right. Let's make it |
Aren't we throwing away a lot of the information here? |
@straight-shoota Oh, and Again, in Ruby:
|
@RX14 Not really. All the information is expressed in the string representation. The data structures are just pretty complicated which makes it look like there is a whole lot more information in it. @asterite |
Maybe we should really rename |
* Add Socket::IPAddress#pretty_print and #inspect * fixup! Add Socket::IPAddress#pretty_print and #inspect
No description provided.