I was trying to run the following code:
puts "3a060dbf8d1a5ac3e67bc8f18843fc48".to_i(16)
This throws an error "Invalid Int32".
After some digging around in the String doc page I found the method I needed was to_big_i(16).
Like this:
puts "3a060dbf8d1a5ac3e67bc8f18843fc48".to_big_i(16)
but this throws "Undefined method to_big_i for String". I later found out I had to require the big package because that is where the string method is defined. So this is the working example:
require "big"
puts "3a060dbf8d1a5ac3e67bc8f18843fc48".to_big_i(16)
It makes sense but looking at the docs page it is unclear that I needed to require the "big" module.
I'm sure this happens with other packages because not everything is included in the prelude.cr file.
I think the docs should inform when a method is defined in a different file/module that isn't included by default.
crystal -v
Crystal 0.25.0 (2018-06-15)
LLVM: 5.0.1
Default target: x86_64-apple-macosx
Given the nature of how modules / files are defined, either
1) would be the simplest, and possible to do right now.
I think one solution doesn't exclude the other, having a good code sample in my opinion makes it a lot easier for whoever's reading the docs.
yes, please do open a PR!
Another thing to do, "Invalid Int32" is a bit of a nondescriptive message, we should mention that the number is too large/would overflow.
This can be closed?
Yes, let's close this.
Most helpful comment
Given the nature of how modules / files are defined, either