Thanks for the instant feedback. And apologies for the offensive late-night
manager humour. If only I’d limited it to my workplace… . Aside: I actually
find it difficult to come up with an example for the ternary operator, as I
don’t consider it “the Ruby way”.
Here’s the revision.
···
Q: What do some of Ruby’s symbols mean?
A:
This question is about non-aplhanumeric characters in Ruby code, not about
symbols like :name. For those, see [appropriate link]. Actual explanations
of the concepts behind them is beyond the scope of this answer.
<= < != == > >>
Relational operators, as per most other computer languages. Are often
redefined for use with various classes.
-
-
- / %
Common arithmetic operators. Some are defined also for String, Array
and others.
- / %
-
===
Case comparison operator. Used to select branches in case statements.
<
Class inheritance, as in
class Car < Vehicle
end
<<
Singleton definition. See [appropriate link] for more info.
Also commonly used as a method for appending (e.g. Array and String).
… …
Range definers, as in 0…10 and “a”…“z”
:
Symbol definer, as in :name, where :name.to_s == “name”. See [a/l].
See next item also.
?:
Ternary decision operator, as in C. For example:
return (level == DEBUG) ? “” : detailed_info
{} =>
Hash definition, as in
numstr = { 1 => “one”, 2 => “two”, … }
[]
Array definition, as in
ndays = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ]
%w[]
String-Array converter, as in
dayabbrev = %w[Sun Mon Tue Wed Thu Fri Sat]
dayabbrev == [“Sun”, “Mon”, “Tue”, “Wed”, “Thu”, “Fri”, “Sat”]
//
Regular expression definition, as in
date_re = /(\d\d\d\d)-(\d\d)-(\d\d)/
y, m, d = date_re.match(“2002-12-01”)[1…3]
?!
Suffixes for methods (optional, of course). In general:
method! changes the object (e.g. String.gsub!)
method? returns boolean (e.g. Array.empty?)