Open dukenguyenxyz opened 3 years ago
Even though I think it's a good idea to have a way to format it like that, I don't think the default should be that. If you see "1001" in the output of "to_s" you might think it's a number, when it's not.
Providing an unambiguous representation is #inspect
's job. #to_s
is supposed to provide a natural representation. A series of 1 and 0 seems like a very natural representation to me. I'm not sure if that's definitely better for to_s
, though. I don't think this type is used often for direct user presentation.
So maybe it could help if you could tell a bit about your use case, @dukeraphaelng?
Currently BitArray.to_s is outputting in the format
BitArray[00000]
https://github.com/crystal-lang/crystal/blob/f0901e1c825de1095d77998ffe8890bfca66def0/src/bit_array.cr#L212-L226
It would be more convenient and make more sense to have the output format similar to Int.to_s - so that it can be converted from a base 2 digit into a number of a different base, i.e.
If we want the string representation explicitly stated in the string, then we can use
.inspect
(keep the current implementation):