Catalog / Ruby Programming Language Cheatsheet
Ruby Programming Language Cheatsheet
A comprehensive cheat sheet covering essential Ruby syntax, data structures, control flow, and object-oriented programming concepts.
Ruby Basics
Syntax
Comments |
|
Variables |
|
Constants |
|
String Interpolation |
|
Blocks |
|
Methods |
|
Data Types
Numbers: Integers ( |
Strings: |
Booleans: |
Symbols: |
Arrays: |
Hashes: |
Nil: |
Operators
Arithmetic |
|
Comparison |
|
Logical |
|
Assignment |
|
Control Flow
Conditional Statements
If Statement
|
Unless Statement
|
Ternary Operator
|
Case Statement
|
Loops
While Loop
|
Until Loop
|
For Loop
|
Each Iterator (Array/Hash)
|
Loop Control |
Exception Handling
|
Object-Oriented Programming
Classes and Objects
Class Definition
|
Creating Objects
|
Attributes (Instance Variables)
|
Instance Methods
|
Class Methods
|
Constructor (initialize method)
|
Inheritance
Inheriting from a Class
|
Calling Superclass Methods
|
Modules
Module Definition
|
Including Modules
|
Extending Modules
|
Using Modules as Namespaces
|
Common Methods
String Methods
|
Returns the length of the string. |
|
Converts the string to uppercase. |
|
Converts the string to lowercase. |
|
Removes leading and trailing whitespace. |
|
Splits the string into an array based on the delimiter. |
|
Checks if the string contains the substring. |
Array Methods
|
Returns the number of elements in the array. |
|
Adds an element to the end of the array. |
|
Removes and returns the last element of the array. |
|
Removes and returns the first element of the array. |
|
Adds an element to the beginning of the array. |
|
Checks if the array contains the element. |
Hash Methods
|
Returns the number of key-value pairs in the hash. |
|
Returns an array of all keys in the hash. |
|
Returns an array of all values in the hash. |
|
Checks if the hash contains the key. |
|
Checks if the hash contains the value. |
|
Deletes the key-value pair from the hash. |