added by Harold T. Harper · updated 19h ago
The Well-Grounded Rubyist
puts adds a newline to the string it outputs if there isn’t one at the end already; print doesn’t. print prints exactly what it’s told to and leaves the cursor at the end.
from The Well-Grounded Rubyist by Joe Leo
Harold T. Harper added 3mo ago
The objects true and false often serve as return values for conditional expressions. The object nil is a kind of “nonobject” indicating the absence of a value or result. false and nil cause a conditional expression to evaluate as false; all other objects (including true, of course, but also including 0 and empty strings) cause it to evaluate to tru
... See morefrom The Well-Grounded Rubyist by Joe Leo
Harold T. Harper added 3mo ago
Instance variables, which serve the purpose of storing information within individual objects, always start with a single at-sign (@) and consist thereafter of the same character set as local variables—for example, @age and @last_name.
from The Well-Grounded Rubyist by Joe Leo
Harold T. Harper added 3mo ago
Global variables are recognizable by their leading dollar sign ($)—for example, $population.
from The Well-Grounded Rubyist by Joe Leo
Harold T. Harper added 3mo ago
Constants begin with an uppercase letter.
from The Well-Grounded Rubyist by Joe Leo
Harold T. Harper added 3mo ago
They’re not always optional, though, particularly when you’re stringing multiple method calls together, so it’s good to lean toward using them rather than leaving them out. You can make an exception for common or conventional cases where parentheses are usually excluded, like calls to puts. But when in doubt, use parentheses.
from The Well-Grounded Rubyist by Joe Leo
Harold T. Harper added 3mo ago
Examples of Ruby expressions and the values to which they evaluate
from The Well-Grounded Rubyist by Joe Leo
Harold T. Harper added 3mo ago
The return value of any method is the same as the value of the last expression evaluated during execution of the method.
from The Well-Grounded Rubyist by Joe Leo
Harold T. Harper added 3mo ago
Thus the result of that calculation provides the return value of the method.
from The Well-Grounded Rubyist by Joe Leo
Harold T. Harper added 3mo ago