But I need to
quote the right parenthesis: \) ... )
String contains many highly useful methods. Refer to http://ruby-doc.org for an
extensive listing of everything you can do with String.
Symbol
Symbols are mostly like Strings, except that they are immutable and one Symbol will always be
the same as any other symbol with the same name. Symbols are used to identify names of different
kinds, and they make it more explicit when you??™re dealing with a specific value. This is a
huge difference compared to Java, where Strings are usually interned (meaning that different
String literals with the same content will refer to the same String instance), and can never be
modified. In Ruby, Symbols are closer to interned Java Strings, and Ruby Strings look like Java
StringBuffers.
You prefix a Symbol with a colon:
:hello_world
You can use double quotes around the name of a Symbol, if it contains things that wouldn??™t
parse otherwise:
:"this is one symbol"
You can create a Symbol with an interpolated name because they??™re double quotes:
:"this is symbol ##{13*13}"
Fixnum and Bignum
Ruby integer numbers are represented with the classes Fixnum and Bignum. In most cases it??™s
transparent to the programmer what class is actually used. Fixnums will turn themselves into
Bignums when the result of an operation gets too big for Fixnum. Both support the same operations,
and you can do all mathematics you would expect to be able to by using Java primitives.
APPENDIX A ?– RUBY FOR JAVA PROGRAMMERS 292
One of the things that can make Ruby code more readable is the ability to include arbitrary
amounts of underscores in a numeric literal:
num = 1_000_000_000
The variable num will contain the number one billion, and the underscores will be stripped
away, but the code is much more readable in this way.
Pages:
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429