Ruby Cheat Sheet 2018 Pdf
Ruby Debugging Magic Cheat Sheet 25 Jan 2016 This document is all about deciphering behavior of Ruby code using nothing but Ruby code. I recommend you get familiar with a debugger like pry-debugger, this doc doesn’t go into debuggers because they’re not always available. Other Ruby libraries cheatsheets. Factory Bot cheatsheet Meta-tags gem cheatsheet Ronn cheatsheet Slim cheatsheet Chunky PNG cheatsheet Do gem cheatsheet Top cheatsheets. Elixir cheatsheet ES2015+ cheatsheet React.js cheatsheet Vimdiff cheatsheet Vim cheatsheet.
Information Types:
Ruby has a few different types of information types; below are some examples of what defines each and how they're properly formatted.
Strings: Anything within quotes are considered strings.
Numbers: More commonly referred to as integers, are simply written as digits.
Booleans: Something that results in either a true or false condition.
Arrays: 'Lists' of items in which each item within the brackets are elements which coorespond to specific positions beginning with '0'.
Hashes: Detailed lists in which each key, (characters in quotes) point to a specific value, (key/value pairs).
'Hello World!'
12345
true/false
groceries = ['Milk', 'Eggs', 'Cheese', 'Bread']
menu = {'Pizza' => 3.50, 'Pasta' => 5.50, 'Soda' => 0.99}
Ruby Cheat Sheet Pdf
Methods/Operators:
In Ruby, everything is an object, in order for objects to talk to one another there are what are called 'Methods'. Methods provide action to have performed on an object to actually 'do' something in code.
In Ruby, there are two central types of operators: Arithmetic and Comparison Operators. Arithmetic operators allow mathematical equations to be performed, whereas comparison operators allow the ability to compare between two objects.
String Methods: .reverse, .capitalize, .upcase, .downcase, .swapcase
Number Methods: .between?, .next, .odd?, .even?
Array Methods: .delete, .count, .join
Hash Methods: .compare, .flatten
Number Operators: +, -, *, /, **, %
Comparison Operators: , , !=, ||, &&, !, ?, :, <, >, <=, >=
General Ruby Syntax:
In Ruby, the general format of creating working code is as follows below:
def year(current)
puts 'It's #{current}!'
end
year(2015)
>> It's 2015!
def = states we're defining a method variable called 'year'.
year = a variable created to represent the name of the method.
(current) = considered a 'Parameter' that the user can pass in a value by calling it, (as we will in the last line).
puts = allows the string 'It's 2015!' to be displayed on the user-console.
end = closes the defined method tag.
year(2015) = 'passes in' the variable 2015 into 'current', which then is interpolated within the #{} syntax of the puts line to output the next line.
Displaying to Console:
In Ruby, there are a few ways to display content to the user after a program runs.
puts = DOESN'T return the value of the method/variable, DOES print to console, & DOES automatically return a new line after the return statement.
print = puts = DOES return the value of the method/variable, DOES print to console, & DOES automatically return a new line after the return statement.
p = DOESN'T return the value of the method/variable. DOES print to console, & DOESN'T automatically return a new line after the return statement.
Below are some examples of how they differ:
puts 'Kunal'
>>Kunal
>>nil
print 'Kunal'
>>Kunalnil
p 'Kunal'
>>'Kunal'
>>'Kunal'
Ruby is an easy language to learn, but it's often necessary to look up something we've forgotten. A combination of Google plus any Ruby books we have on our shelves can help, but sometimes it's handy to refer to a simpler set of notes - such as a 'cheat sheet.' This post attempts to cover the most interesting ones.
The idea for this initial list came from Scott Klarr's own list. Scott has been quite prolific lately in putting together lists of cheat sheets. Some of his lists are: Apache cheat sheets, MySQL cheat sheets, PHP cheat sheets, and JavaScript / AJAX cheat sheets.
On with the Ruby cheat sheets:
'Essential Ruby' RefCard (PDF)
Essential Ruby is a combination of a cheat sheet and a tutorial. It's six pages long, but features a mini Ruby introduction and tutorial, as well as the myriad of tables you'd expect from a cheat sheet. It's like a whole Ruby beginner's reference and tutorial in a single PDF. The only 'catch' is that you need to be a user of DZone (the 'Digg for Developers') or JavaLobby to get it, but there's a very simple signup form you can fill in if you're not.
Ruby Cheatsheet (PDF and PNG)
This cheat sheet (homepage) covers types, exceptions, expressions, variable types, operators and precedence, constants, regular expressions, predefined / special variables, arguments accepted by the Ruby interpreter, reserved words, and a large collection of Object, String, Kernel, Array, Hash, Test::Unit, File, Dir and DateTime methods. Extremely suitable for printing and/or wall chart use.
Ruby QuickRef (HTML)
Ruby On Rails Cheat Sheet
I often use this one myself! A ridiculously comprehensive 'cheat sheet' created by Ryan Davis covering syntax rules, reserved words, regular expression terminology, class and method definitions, predefined variables and constants, control and logic expressions and formations, exceptions, the standard library, and a whole ton of useful stuff.
Ruby Code Cheat Sheet
Download oracle virtualbox for mac. Ruby Reference (PDF)
More of an extremely brief reference than a truly comprehensive cheat sheet, but still useful, especially for beginners. 5 pages long, so not suitable for printing (Also available to view on the Web at Scribd.)
Cheat: Ruby Cheat Sheets on your Terminal! (Application)
Not a cheat sheet, but an application (gem install cheat) that provides cheat sheet type reference material on your terminal (from 228 source cheat sheets!) Developed by the great guys over at Err Free.
A Beginner's Notes (HTML)
A set of notes made by a beginning Ruby developer as he works his way through a Ruby manual.
Ruby Command Line Parameters Cheat Sheet (HTML)
A simplified list of the command line options offered by the Ruby interpreter.
Ruby Array Cheat Sheet
Strftime Parameters (HTML)
Ruby Cheat Sheet 2019
A handy guide to the formatting parameters accepted by strftime. I commonly have to look these up myself!