Things under legendu

Array¶
The method
pushinserts an element to the back of the arry; the methodinsertinserts an element to any place of the array.The method
popremoves the last element of the array; the methoddeleteremoves any specified element from the array.The method
concatcombines the array with another one; the methodjoinconcatenates all elements in the array separated by the specified delimiter.
String¶
Use the method
to_ito convert a string to integer.You use both single and double quotes to denote string. The difference is that single quotes preserves escape characters while double quotes interprete escape characters.
The method
end_with?check whether a string ends with the specified string.The method
upcasereturns a copy of the string with lower case letters replaced with their upper case letters; the methoddowncasereturns a copy of the string with upper case letters replaced with their lower case letters; the methodswapcasereturn a copy of the string with lower case letters replaced with their upper case letters and upper case character replaced with their lower case letters.Use the method
stripto remove leading and trailing white spaces.
Input and Output¶
Both the function
putsandprintdisplay the content of objects on the console. The difference is that the functionputsadd a new line to the end if their is no one whileprintnot.The function
getsread in input from the console. You can use thechompmethod to ignore new lines, i.e., you can usegets.chompto read a single line from the console.
File and Directory¶
You can use the method
Dir.entriesto query files and subdirectories in a directory.The method
File.deleteremoves files specified files. The number of files passed as arguments is returned.
Flow Control¶
You cannot use
else ifin Ruby, instead you can useelsif.
Object and Class¶
Use
methodsto query all methods of an object.You’d not define a function with the same as some directly usable function/method in Ruby.