You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
defto_s(io : IO) : Nil
each do |value|
io << (value ?'1' : '0')
endend
If we want the string representation explicitly stated in the string, then we can use .inspect (keep the current implementation):
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]
crystal/src/bit_array.cr
Lines 212 to 226 in f0901e1
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):The text was updated successfully, but these errors were encountered: