Base62 Encoding Short Codes Discussion
Hi Chris,
why the local variable result is treated as frozen?
Here is the error:
Error:
ShortCodeTest#test_encode_10:
FrozenError: can't modify frozen String: ""
app/models/short_code.rb:20:in prepend'
encode'
app/models/short_code.rb:20:in
test/models/short_code_test.rb:15:in `block in class:ShortCodeTest'
Sounds like you have a bug somewhere. Have you compared your code to the repository?
the code is the same. If I initialize the local variable result with:
result =+"" or result = String.new
no errors, tests passing
In my case works as expected, so compare again as suggested by Chris or maybe check ruby or rails version
Chris,
I am very curious upon your decision to prepend the characters to the result string, instead of appending?
This version is a bit shorter.
while number > 0
number, remainder = number.divmod(BASE)
result.prepend(CHARACTERS[remainder])
end