The "Unknown:"s below indicate that an entry is incomplete.
foo ... end where foo in { if, do, ... } | block (grouping statements, especially when statements are not expressions) |
\ | breaking lines (useful when end-of-line and/or indentation has a special meaning) |
# | commenting (until end of line) |
< > <= >= | comparison |
a <=> b | comparison (returns 3 values (i.e. inferior, equal or superior)) |
=begin ... =end | documentation comment |
== != | equality / inequality (deep) |
GC.start | force garbage collection |
( ... ) | grouping expressions |
begin ... end | grouping expressions |
__LINE__ __FILE__ | information about the current line and file |
eval | runtime evaluation |
case-sensitive | tokens (case-sensitivity (keywords, variable identifiers...)) |
[A-Z][_a-zA-Z0-9]* | tokens (constant regexp (if different from variable identifier regexp)) |
[_a-zA-Z][_a-zA-Z0-9]*[!?]? | tokens (function identifier regexp (if different from variable identifier regexp)) |
[_a-z][_a-zA-Z0-9]* | tokens (variable identifier regexp) |
CamelCase for modules and classes, ALL_CAPS for constants, underscores for functions, variables, ... | tokens (what is the standard way for scrunching together multiple words) |
= | variable assignment or declaration (both) |
{|a, b| ... }(1) | anonymous function |
proc {|a, b| ...} | anonymous function |
lambda {|a, b| ...} | anonymous function |
f(a,b,...) | function call |
f[a,b,...] or f.call(a,b,...) | function call |
f | function call (with no parameter) |
f[] or f.call | function call (with no parameter) |
method_missing | function called when a function is not defined (in dynamic languages) |
def f(para1, para2, ...) ... end | function definition |
return(2) | function return value (breaks the control flow) |
no syntax needed(3) | function return value (function body is the result) |
caller | runtime inspecting the caller information |
next / break(4) | breaking control flow (continue / break) |
redo / retry | breaking control flow (redo / retry) |
return(2) | breaking control flow (returning a value) |
callcc | call-with-current-continuation |
rescue | exception (catching) |
ensure | exception (cleanup: code executed before leaving) |
retry | exception (retrying: after catching an exception, tell the snippet to be re-run) |
raise | exception (throwing) |
if c then ... end | if_then |
... if c | if_then |
c and ... | if_then |
if c; ... end | if_then |
if c ... end | if_then |
if c then b1 else b2 end | if_then_else |
case when c; b1 when c2; b2 else b3 end | if_then_else |
c ? b1 : b2 | if_then_else |
if c b1 elsif c2 b2 else b3 end | if_then_else |
begin ... end until c | loop (do something until condition) |
10.downto(1) {|i| ... } | loop (for each value in a numeric range, 1 decrement) |
(1..10).each {|i| ... } | loop (for each value in a numeric range, 1 increment (see also the entries about ranges)) |
1.upto(10) {|i| ... } | loop (for each value in a numeric range, 1 increment (see also the entries about ranges)) |
(1..10).step(2) {|i| ... } | loop (for each value in a numeric range, free increment) |
loop | loop (forever loop) |
while (c) ... | loop (while condition do something) |
case val when v1; ... when v2, v3; ... else ... end | multiple selection (switch) |
; | sequence |
end-of-line | sequence |
super | accessing parent method |
class | class declaration |
self | current instance |
class | get the type/class corresponding to an object/instance/value |
respond_to? | has the method |
class child < parent end | inheritance |
object.method(para) | method invocation |
object.method | method invocation (with no parameter) |
methods | methods available |
o.clone(5) | object cloning |
class_name.new(...) | object creation |
is_a? kind_of? | testing class membership |
module P ... end | declare |
append_features | declare (selective export) |
include or even extend | import (everything into current namespace) |
require "p" | import (package (ie. load the package)) |
. | package scope |
:: | package scope |
s[n] | accessing n-th character |
chr | ascii to character |
?z | character "z" |
s[0] | character to ascii |
to_s, to_str, inspect, String() | convert something to a string (see also string interpolation) |
* | duplicate n times |
s[n..m] | extract a substring |
s[n,len] | extract a substring |
index | locate a substring |
rindex | locate a substring (starting at the end) |
all strings allow multi-line strings | multi-line |
Marshal.dump | serialize (marshalling) |
simple print (on any objects) | |
p(6) | simple print (on any objects) |
puts(7) | simple print (on any objects) |
printf | simple print (printf-like) |
sprintf | sprintf-like |
% | sprintf-like |
+ | string concatenation |
== != | string equality & inequality |
equal? | string equality & inequality |
length | string size |
size | string size |
"\n" | strings (end-of-line (without writing the real CR or LF character)) |
"... #{v} ..." "... #$v ..." "... #@v ..." "... #@@v ..." | strings (with interpolation of variables) |
<<MARK ... #{v} ... MARK | strings (with interpolation of variables) |
%Q(...(... #{v} ...)...), %Q[...], %Q{...}, %Q<...>, %Q/.../ | strings (with interpolation of variables) |
'...' | strings (with no interpolation of variables) |
<<'MARK' ... MARK | strings (with no interpolation of variables) |
%q(...(...)...), %q[...], %q{...}, %q<...>, %q/.../ | strings (with no interpolation of variables) |
String | type name |
Marshal.load | unserialize (un-marshalling) |
upcase / downcase | upper / lower case character |
upcase / downcase | uppercase / lowercase / capitalized string |
false | false value |
nil | false value |
! | logical not |
not(8) | logical not |
|| / && | logical or / and (short circuit) |
or / and | logical or / and (short circuit) |
true | true value |
anything not false | true value |
transpose | 2 lists from a list of couples |
a.insert(i, e) | adding an element at index (side-effect) |
unshift | adding an element at the beginning (list cons) (side-effect) |
push | adding an element at the end (side-effect) |
inject | f(... f(f(init, e1), e2) ..., en) |
find | find an element |
detect | find an element |
each | for each element do something |
for v in l ... | for each element do something |
shift | get the first element and remove it |
pop | get the last element and remove it |
member? | is an element in the list |
include? | is an element in the list |
any? | is the predicate true for an element |
all? | is the predicate true for every element |
each_with_index | iterate with index |
l.join(s) | join a list of strings in a string using a glue string |
l * s | join a list of strings in a string using a glue string |
find_all | keep elements (matching) |
select | keep elements (matching) |
reject | keep elements (non matching) |
a[-1] | last element |
+ | list concatenation |
[ a, b, c ](9) | list constructor |
flatten | list flattening (recursive) |
zip | list of couples from 2 lists |
transpose | list of couples from 2 lists |
to_a | list out of a bag |
size | list size |
length | list size |
a[i] | list/array indexing |
slice | list/array indexing |
assoc | lookup an element in a association list |
partition | partition a list: elements matching, elements non matching |
uniq | remove duplicates |
uniq! | remove duplicates |
reverse | reverse |
min / max | smallest / biggest element |
sort(10) | sort |
sort! | sort |
sort_by | sort |
map | transform a list (or bag) in another one |
collect | transform a list (or bag) in another one |
a or [a] | computable tuple (these are a kind of immutable lists playing a special role in parameter passing) (1-uple) |
[] | computable tuple (these are a kind of immutable lists playing a special role in parameter passing) (empty tuple) |
*t | computable tuple (these are a kind of immutable lists playing a special role in parameter passing) (using a tuple for a function call) |
fetch | dictionary (access: read) |
h[k] | dictionary (access: read/write) |
store | dictionary (access: write) |
{ a => b, c => d } | dictionary (constructor) |
{ a, b, c, d } | dictionary (constructor) |
Hash[ a, b, c, d ] | dictionary (constructor) |
has_key?, include?, key?, member? | dictionary (has the key ?) |
keys | dictionary (list of keys) |
values | dictionary (list of values) |
merge(11) | dictionary (merge) |
update(11) | dictionary (merge) |
delete | dictionary (remove by key) |
Hash | dictionary (type name) |
|| | optional value (null coalescing) |
nil | optional value (null value) |
v | optional value (value) |
a ... b | range (inclusive .. exclusive) |
a .. b | range (inclusive .. inclusive) |
. | record (selector) |
a, b, c | tuple constructor |
+ / - / * / / | addition / subtraction / multiplication / division |
& / | / ^ | bitwise operators (and / or / xor) |
~ | bitwise operators (bitwise inversion) |
<< / >> | bitwise operators (left shift / right shift / unsigned right shift) |
divmod | euclidean division (both quotient and modulo) |
** | exponentiation (power) |
log10 | logarithm (base 10) |
log | logarithm (base e) |
remainder | modulo (modulo of -3 / 2 is -1) |
% | modulo (modulo of -3 / 2 is 1) |
modulo | modulo (modulo of -3 / 2 is 1) |
- | negation |
1000.0, 1E3 | numbers syntax (floating point) |
1_000, 10_00, 100_0 | numbers syntax (integer thousand-separator) |
0b1, 07, 0xf(12) | numbers syntax (integers in base 2, octal and hexadecimal) |
1000 | numbers syntax (integers) |
mathematical | operator priorities and associativities (addition vs multiplication) |
mathematical | operator priorities and associativities (exponentiation vs negation (is -3^2 equal to 9 or -9)) |
rand | random (random number) |
srand | random (seed the pseudo random generator) |
sqrt / exp / abs | square root / e-exponential / absolute value |
sin / cos / tan | trigonometry (basic) |
asin / acos / atan(13) | trigonometry (inverse) |
to_i, Integer() / round / floor / ceil | truncate / round / floor / ceil |
Float | type name (floating point) |
Integer, FixNum, BigNum | type name (integers) |