You are on page 1of 2

Predefined Variables

Ruby arguments

$!

Exception information

-c

Check

$@

Array of backtrace

-d

Debug

$&

String of last match

-e

One Line

$`

String left of last match

-h

Help

Str right of last match

-n

gets loop

Types

Expressions

Variables

$+

Last group of last match

-rL

require L

12345

if expr [then]
elsif expr
[then]
else
end

local

$N

Nth group of last match

-v

verbose

@instance

$~

Info about last match

-w

warnings

@@class

$=

Case insensitive flag

-y

comp debug

CONSTANT

$/

Input record separator

$\

Output record separator

Reserved Words

$,

Output field separator

alias

$.

Line number of last file

and

$>

Default output

BEGIN

$_

Last input line of string

begin

$*

Command line args

break

$0

Name of script

case

$$

Process number

class

Module names loaded

def

$stderr

Standard error output

defined?

$stdin

Standard input

do

$stdout

Standard output

else

123.45
1.23e-4
0xFF00

1...5

unless expr
[then]
else
end

Operators and
Precedence

a..z

expr if expr

::

a...z

expr unless
expr

[]

0b01100
1..5

string sq
string dq
#{expr}
\t\r\n
%q(string sq)
%Q(string dq)
%(string dq)
<<id string id
:symbol
/regex/opt
%r|regex|
[1, 2, 3]
%w(1 2 3)
%W(1 2 #{expr})
{1=>2, :s=>v}

case expr
when comp
else
end

+ - ! ~

while expr [do]


end

&

until expr [do]


end
do
while expr
do
until expr
for var in expr
[do]
end
expr.each [do]
end
break next redo
retry

Exceptions
begin
rescue ex =>
var
else
ensure
end
StandardError
ZeroDivisionError
RangeError
SecurityError
IOError
IndexError
RuntimeError

**

Module/Class
module Name
end
class Name
end
class Name <
Sup
end
class << obj
end
def
name(args...)
end
def inst.
name(...)
end
public
protected
private
attr_reader
attr_writer
attr
attr_accessor

* / %
<< >>
| ^
> >= < <=
<=> == === !=
=~

elsif

&&

Regex

.. ...

all characters

end

= ( += -= )

[ ]

any single char in set

ensure

not

[^ ]

any single char not in set

false

and or

zero or more

for

one or more

if

zero or one

in

alteration

module

( )

Group

next

Beginning of line or str

nil

End of line or string

not

{1,5}

1 to 5

or

\A

Beginning of a string

redo

\b

Word boundary

rescue

\B

Non-word boundary

retry

\d

digit, same as [0..9]

return

\D

Non-digit

self

\s

Whitespace

super

\S

Non-whitespace

then

\w

Word-character

true

\W

Non-word-character

undef

\z

End of a string

unless

\Z

End of string, before nl

until

Constants
__FILE__
__LINE__
ENV
ARGF
ARGV

END

when
while
yield

alias new old

2006 mb@cenophobie.com available free from www.cenophobie.com/ruby

Object

Array

File

Obj#class -> class

Array::new (int [,obj]) -> array

File#new (path, modestring)-> file

Obj#freeze -> object

Array#clear

Obj#frozen? -> true or false

Array#map! do |x| ... end

File#new (path, modestring) do


|file| ... end

Obj#inspect -> string

Array#delete (value) -> obj or nil

Obj#is_a? (class) -> true or false

Array#delete_at (index)-> obj or n

Obj#methods -> array

Array#delete_if do |x| ... end

Obj#respond_to? (sym) -> true or


false

Array#each do |x| ... end

File#basename (path [,suffix]) ->


string

Array#flatten! -> array

File#delete (path, ...)

Obj#to_s -> string

File#open (path, modestring) do


|file| ... end
File#exist? (path) -> t or f

Array#include? (value) -> t or f

File#rename (old, new)

Array#insert (idx, obj...)-> array

File#size (path) -> integer

String

Array#join ([string]) -> string

Read-only, from beginning

Str#[num, num/range/regx] -> str

Array#length -> integer

r+

Read-write, from beginning

Str#capitalize! -> string

Array#pop -> obj or nil

Write-only, trunc. / new

Str#center (int [,str]) -> str

Array#push (obj...) -> array

w+

Read-write, trunc. / new

Str#chomp! ([str]) -> str


Str#count -> integer
Str#delete! ([string]) -> string
Str#downcase! -> string
Str#each ([str]) do |str| ... end
Str#each_line do |line| ... end
Str#gsub! (rgx) do |match| ... end
Str#include? (str) -> true / false
Str#index (str/reg [,off]) -> int
Str#insert (int, string) -> string
Str#length -> integer
Str#ljust (int [,padstr]) -> str

Write-only, from end / new

Hash

a+

Read-write, from end / new

Hash#clear

Binary (Windows only)

Hash#delete (key) -> obj or nil


Hash#delete_if do |k, v| ... end

Dir

Hash#each do |k, v| ... end

Dir[string] -> array

Hash#has_key? (k) -> true or false

Dir::chdir ([string])

Hash#has_value? (v) -> t or f

Dir::delete (string)

Hash#index (value) -> key

Dir::entries (string) -> array

Hash#keys -> array

Dir::foreach (string) do |file|


... end

Hash#length -> integer

Str#rindex (str/reg [,off]) -> int

Hash#select do |k, v| ... end ->


array

Str#rjust (int [,padstr]) -> str

Hash#values -> array

Str#scan (rgx) do |match| ... end

Dir::getwd -> string


Dir::mkdir (string)
Dir::new (string)
Dir::open (string) do |dir| .. end

Str#split (string) -> array

Test::Unit

Dir#close

Str#strip! -> string

assert (boolean [,msg])

Dir#pos -> integer

Str#sub! (rgx) do |match| ... end

assert_block (message) do ... end

Dir#read -> string or nil

Str#swapcase! -> string

assert_equal (expected, actual


[,msg])

Dir#rewind

Str#to_sym -> symbol


Str#tr! (string, string) -> string
Str#upcase! -> string
Kernel

assert_in_delta (exp, act, dlt


[,message])
assert_kind_of (klass, object
[,msg])

block_given?

assert_match (pattern, string


[,msg])

eval (str [,binding])

assert_nil (object [,msg])

raise (exception [,string])

assert_no_match (pattern, string


[,msg])

fork do ... end => fixnum or nil


proc do ... end => proc
print (obj)
warn (msg)

assert_not_equal (expected, actual


[,msg])

DateTime
DateTime::now
DateTime::parse (str)
DateTime::strptime (str, format)
DateTime#day
DateTime#hour
DateTime#leap?
DateTime#min
DateTime#month

assert_not_nil (object [,msg])

DateTime#sec

assert_not_same (expected, actual


[,msg])

DateTime#wday
DateTime#year

assert_respond_to(obj, method
[,msg])
assert_same (expected, actual
[,msg])

Ruby: www.ruby-lang.org
Doc: www.ruby-doc.org

2006 mb@cenophobie.com available free from www.cenophobie.com/ruby

You might also like