Cheatography
https://cheatography.com
This interview Q&A cheat sheet offers a quick, easy reference to key interview strategies and commonly asked questions. Use it to refresh your preparation and boost your confidence before any interview!
This is a draft cheat sheet. It is a work in progress and is not finished yet.
What is Ruby?
Ruby is a strongly object-oriented language, which means that absolutely everything in Ruby is an object, even the most basic data types. |
- It is simple & readable language |
- Implemented based on python and perl |
- Ruby follows convention over configuration and DRY |
Convention Over Configuration and DRY
COC: The method names and variable names should match the logic |
DRY: If same code implements 2 or more scenario used method & called method |
Method Overloading & Method Overriding
Overloading: A class containing more methods with same name with different parameters |
Overriding: Parent class and child class having same name with differnt functionalities. when you call, it executes parent class only. |
RVM(Ruby version Manager)
It is a command line tool allows easily to install, manage & work with different ruby environments |
|
|
sub VS gsub
sub: It will replace first matching item |
Ex: I love cats. cats are great |
O/p: I love dogs. cats are great |
gsub: It will replace all matching item in sentence |
Ex: I love cats. cats are great |
O/p: I love dogs. dogs are great |
Hash VS Array
Hash: Key-Value pair combination. Key should be unique |
Array: Collection of stings, numbers. Index starts with '0'. It is Heterogenous |
Include VS Extend
Include: We need objects to call methods |
Extend: We dont need to objects to call methods, directly we can call with class. |
Class VS Module
Class: Class is a blueprint of object |
Module: It is collection of class |
Procs VS lamda
Proc(Procedure): It is code block that stored in local variable, not in method. |
Lamda: It is Short block of code which takes in parameters & returns value. |
|
|
Self
- Self refers to current object instance |
- It is used to access methods & variables within object itself. |
nil vs false
nil: Object represents nothing or no value |
false: Boolean value that explicitly represents falsehood. |
puts vs print vs p
puts: Output a string with newline at end. |
print: Output a string without newline |
p: Output value is more readable form, shows exact values including quotes. |
|