Built-in Functions

Strictly speaking, they aren't functions in Ruby, but since methods defined in the Kernel module can be called from anywhere, they can be used like functions are in other languages. Carefully consider the repercussions of redefining the methods here.

block_given?

Returns true when the method has been supplied with a block; otherwise, returns false. See Iterator for details.

catch(tag) {|tag| .... }

Executes the block and returns its value. If a throw with the same name as tag takes place while the block is running, the return value will be that throw's second argument.

break cannot break out all nested loops at once. Use catch in these circumstances.

catch(:loop1) {
  for i in 1..2
    for j in 1..2
      throw :loop1, j
    end
  end
}
eval(expr)

Evaluate the string expr as a Ruby program and returns the result.

exit

Exits a running Ruby program.

exit throws a SystemExit exception to terminate the program, so it can be trapped by a rescue clause where necessary.

loop { ... }

Evaluates a block in an infinite loop (until explicitly terminated).

open(file[, mode])
open(file[, mode]) {|io| ... }

Opens file and returns a File object. mode specifies one of the following strings. When mode is omitted, the default is "r".

Using "+" opens the file in read-write mode (RDWR):

The "b" flag can also be added to any of these (in the format "r+b") to open the file in binary mode.

When open is called along with a block, it opens the file, executes the block, then closes the file when execution is complete. In this case, returns the result of the block evaluation. That is:

open(path, mode) do |f|
   ...
end

# almost identical to the above
f = open(path, mode)
begin
   ...
ensure
  f.close
end
p(obj, [obj2, ...])

Outputs obj in a human-readable format. Identical to the following code (see Object#inspect):

print obj.inspect, "\n", obj2.inspect, "\n", ...

In Ruby, the usual output destination would be standard output. This method is redefined in RGSS to output to a Windows message box.

Returns nil.

print(arg[, ...])

Prints the arguments in order. If a non-string object has been supplied as an argument, it will be converted into a string with to_s and printed. However, if the argument is nil, it will print the string "nil".

In Ruby, the usual output destination would be standard output. This method is redefined in RGSS to output to a Windows message box.

Returns nil.

raise
raise(message)
raise(exception)
raise(error_type, message)

Throws an exception. See raise for details.

rand(max)

Creates a random integer in the range 0 ≤ integer < max. Automatically calls srand if it hasn't already been called.

If max is nil or 0, uses Float to return a random number in the range 0 ≤ real number < 1.

sprintf(format[, arg[, ...]])

Interprets the string format as does C's sprintf, returning a string of formatted arguments.

See sprintf Format for details.

srand([seed])

Sets the rand random number seed and returns the old initial value. If seed is omitted, uses the current time (or a similar value) as the seed.

throw(tag[, value])

Escapes (across methods) to the end of a catch block with the same tag. If there is no catch with the same tag, the thread terminates with NameError. value will be the return value of the catch.

Converted from CHM to HTML with chm2web Pro 2.85 (unicode)