Like C , does ruby have signed and unsigned integers and if it does then does that mean length method of String class return signed integer ? (Since in C integer if not specified implies signed)
问题:
回答1:
Ruby implements integers in such a way that the distinction signed/unsigned is irrelevant, as Ruby integers extend automatically into BigNum (arbitrary length integers) when applicable.
This effectively prevents integer overflow, which is IMHO the main reason why people care about signedness in languages with fixed-size integers like C.
回答2:
Since types are dynamic in Ruby, forcing Ruby to store a numerical value as a specific format is meaningless.
Ruby will store integers by its internal mechanism. So, let Ruby decide how to store your number.
回答3:
No.
As the documentation tells you:
Ruby supports integers and floating point numbers. Integers can be any length (up to a maximum determined by the amount of free memory on your system).
These integers are always signed.