Don't forget to bookmark us! Press CTRL+D / CMD + D  |  

Ruby Language Cheat Sheet

We provide you with all the mostly used Ruby modules and corresponding function and feature list. You can click on the feature and see more details about the feature with example code. We hope you will enjoy the cheat sheet and developer hints very much.

No result found
BasicObject

BasicObject is the parent class of all classes in Ruby. It's an explicit blank class.

BasicObject can be used for creating object hierarchies independent of Ruby's object hierarchy, proxy objects like the Delegator class, or other uses where namespace pollution from Ruby's methods and classes must be avoided.


See more
Class

Classes in Ruby are first-class objects---each is an instance of class Class.

Typically, you create a new class by using:


See more
ENV

ENV is a hash-like accessor for environment variables.

When you get the value for a name in ENV, the value is retrieved from among the current environment variables.

When you create or set a name-value pair in ENV, the name and value are immediately set in the environment variables.

When you delete a name-value pair in ENV, it is immediately deleted from the environment variables.

A String.

An object that responds to #to_str by returning a String, in which case that String will be used as the name or value.

May not be the empty string:

May not contain character "=":

May not be a non-String that does not respond to #to_str:

May not contain the NUL character "\0":

May not have an ASCII-incompatible encoding such as UTF-16LE or ISO-2022-JP:

A Hash returned by an ENV method.

An Enumerator returned by an ENV method.

An Array returned by ::keys, ::values, or ::to_a.

The String returned by ::inspect.

The Array returned by ::shift.

The name returned by ::key.

::replace replaces ENV with a new collection of entries.

::clear empties ENV.


See more
File

A File is an abstraction of any file object accessible by the program and is closely associated with class IO. File includes the methods of module FileTest as class methods, allowing you to write (for example) File.exist?("foo").

In the description of File methods, permission bits are a platform-specific set of bits that indicate permissions of a file. On Unix-based systems, permissions are viewed as a set of three octets, for the owner, the group, and the rest of the world. For each of these entities, permissions may be set to read, write, or execute the file:


See more
IO

The IO class is the basis for all input and output in Ruby. An I/O stream may be duplexed (that is, bidirectional), and so may use more than one native operating system stream.

Many of the examples in this section use the File class, the only standard subclass of IO. The two classes are closely associated. Like the File class, the Socket library subclasses from IO (such as TCPSocket or UDPSocket).

A plain string represents a filename suitable for the underlying operating system.

A string starting with "|" indicates a subprocess. The remainder of the string following the "|" is invoked as a process with appropriate input/output channels connected to it.

A string equal to "|-" will create another Ruby instance as a subprocess.

IO::console

IO#raw

IO#raw!

IO#cooked

IO#cooked!

IO#getch

IO#echo=

IO#echo?

IO#noecho

IO#winsize

IO#winsize=

IO#iflush

IO#ioflush

IO#oflush


See more
Math

The Math module contains module functions for basic trigonometric and transcendental functions. See class Float for a list of constants that define Ruby's floating point accuracy.

Domains and codomains are given only for real (not complex) numbers.


See more
Method

Method objects are created by Object#method, and are associated with a particular object (not just with a class). They may be used to invoke the method within the object, and as a block associated with an iterator. They may also be unbound from one object (creating an UnboundMethod) and bound to another.


See more
Numeric

Numeric is the class from which all higher-level numeric classes should inherit.

Numeric allows instantiation of heap-allocated objects. Other core numeric classes such as Integer are implemented as immediates, which means that each Integer is a single immutable object which is always passed by value.


See more
Range

A Range represents an interval—a set of values with a beginning and an end. Ranges may be constructed using the s..e and s...e literals, or with ::new. Ranges constructed using .. run from the beginning to the end inclusively. Those created using ... exclude the end value. When used as an iterator, ranges return each value in the sequence.

begin of beginless range and end of endless range are nil;

each of beginless range raises an exception;

each of endless range enumerates infinite sequence (may be useful in combination with Enumerable#take_while or similar methods);

(1..) and (1...) are not equal, although technically representing the same sequence.


See more
Try HTML/CSS