General Flashcards
Based on information from http://www.zenspider.com/Languages/Ruby/QuickRef.html
What is a comment in Ruby code?
from # to end of line
A Ruby program is a sequence of…
expressions
How do you terminate an expression?
with a ; or end-of-line
Can an expression go beyond end-of-line?
Yes; if it is parsed as incomplete, parsing continues on next line
Is there a way to force an expression to run past end-of-line unconditionally?
Yes, by ending the line with a backslash \
What are the basic Ruby data types?
numbers, strings, ranges, regexes, symbols, arrays, hashes (and files?)
Can a large integer be broken up for readability?
Yes, with underscores, e.g. 1_000_000
How is a literal hexadecimal value denoted?
With “0x”, C style, e.g. 0xffff
How is a floating-point value expressed
C style, e.g. 1.2e-3
How is a literal octal value expressed
With “0” prefix, C style, e.g. 0377
How is a literal binary value expressed?
With “0b”, e.g. 0b01011
How is the literal value of an ASCII character expressed?
With a “?” prefix and no quotes, e.g. ?a
How is the literal value of an ASCII control character expressed?
Prefixed with “?\C-“, e.g. ?\C-a
How is the literal value of a “meta” character expressed?
Prefixed with “?\M-“, e.g. ?\M-a
What is the simplest way to express strings (non-interpolated, no escaping)?
Single quoted, e.g. ‘string’