Ruby Cheat Sheet
Transform, format, and optimize your data instantly with this free client-side tool.
Basics
Variable assignment
Print with string interpolation
Print without trailing newline
Print inspecting the object (calls .inspect)
Get the class/type of an object
Convert to Integer, String, Float
Control Structures
If / Elsif / Else statement
Inline if statement
Execute if condition is false
Switch/Case statement
Times loop
While loop
Strings
String definition
Convert case
Capitalize first letter
Get string length
Check if includes substring
Split string into array
Global search and replace
Remove leading and trailing whitespace
Arrays
Array definition
Append element to end
Remove and return last element
Prepend element to beginning
Remove and return first element
Create new array with transformed elements
Filter array elements (like filter in JS)
Sum elements in array
Join elements into a string
Hashes
Hash definition (String, Symbol syntax)
Access value by key
Get all keys or values
Check if key exists
Remove key/value pair
Iterate over hash
Methods
Method definition (last evaluated expression is returned)
Method accepting variable number of arguments
Method accepting keyword arguments
Execute passed block if one exists
Classes
Class definition
Constructor method
Create getter and setter methods for @name
Create getter method for @age
Class method definition
Class inheritance
Call parent method with same arguments
Modules
Module definition
Add module methods as instance methods
Add module methods as class methods
Error Handling
Error handling block
Raise an exception manually
File I/O
Read entire file into string
Write string to file
Open file, append securely with block
Check if file exists
Advanced
Explore advanced configurations for Ruby
Performance tuning best practices for Ruby
Run security checks and validation for Ruby
🔥 Similar Tools
Explore LibraryFrequently Asked Questions
Got questions? We've got answers.