Skip to content

Conversation

@fr3nch13
Copy link

The README says that the .to_s method outputs the canonical, but it only includes the address; however, to_string does include the CIDR. This fixes and clarifies the difference.

The README says that the `.to_s` output includes the CIDR, but it doesn't; however, to_string does.
@fr3nch13
Copy link
Author

IPv4

IPv6

@sandstrom
Copy link
Collaborator

sandstrom commented Apr 28, 2025

I'm somewhat hesitant about this, because I'd prefer to deprecate to_string.

I think it's confusing that to_s and to_string exist, and return different things. I've never seen that in any other ruby library.

#132

@sandstrom sandstrom mentioned this pull request Apr 28, 2025
11 tasks
@fr3nch13
Copy link
Author

fr3nch13 commented May 1, 2025

Are planning on replacing to_s with what to_string does now?

I know ruby/ipaddr does the same as your's currently does.

https://github.com/ruby/ipaddr/blob/master/lib/ipaddr.rb#230

@sandstrom
Copy link
Collaborator

Good point!

I didn't know. Are you aware of other libraries having both of these?

Are there any conventions on what the difference between them is 'supposed to be'?

I found this one, but it's about to_str.

https://marcgg.com/blog/2017/01/23/ruby-to-s-to-str/

@fr3nch13
Copy link
Author

fr3nch13 commented Sep 9, 2025

I haven't, but I'm also not a Ruby SR Dev. I'm sure others would have a more Ruby way opinion about how it should be done.

Maybe to_string should be called something else like to_cidr_notation or something (maybe shorter) like that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants