Ruby Basics

Description

Just a bunch of basic ruby syntax + definitions.
Andrei Ilinca
Flashcards by Andrei Ilinca, updated more than 1 year ago
Andrei Ilinca
Created by Andrei Ilinca over 8 years ago
15
1

Resource summary

Question Answer
Int class method: EVEN? Definition + what does it do + and what does it return? It's a method that control if a given integer is even and it's return true or false.....
Int class method: ODD? It's a method that controls if a given integer is even and it's return true or false....
Array method: COUNT arr.count = the return value it's the same as the output (number of el in the array) arr.count(obj) = obj = 7 output and return still the same cioe il numero di volte che l'el obj = 7 si trova nell'arr
Array method: DELETE Destructive method delete(obj) = delete all the obj from the arr that are equal to obj and return the last deleted obj. If the obj given does not exits in the arr returns nil.
Hash method: DELETE Destructive method hsh.delete(key) = delete the key/value pair from hsh and return the value of the given key, return nil if the given key does not exist in the hsh.
Hash method: DELETE_IF Destructive method delete_if {| key, value | block } → hsh Deletes every key-value pair from hsh for which block evaluates to true. If no block is given, an enumerator is returned instead.
String method: CAPITALIZE Not a destructive method str.capitalize = uppercase only the first char and all the rest downcase. works only for chars.
String method: CHARS Not destructive method str.chars = transform the given str in an array of chars.
IF/ELSE/ELSIF if condition == true #execute the first block elsif condition == true #execute this block else #if the above conditions are all false execute this block.
Ternary operator Shortcut for if/else condition all in one line condition = true ? execute block : dont execute this block condition = false ? dont execute this block : execute this block
Show full summary Hide full summary

Similar

Operator Precedence Rules in Ruby
Domhnall Murphy
Interesting Ruby Talks
tosbourn
Programming and Scripting Skills Needed
neteng33
A Simple Program
adriantrainor201
Capitulo 1
cachuan07
Economic burden of rare bone diseases
rpinedo
Variables
Edmond Pruteanu
Classes
Edmond Pruteanu
Ruby format sequences
YourCyborg
Strings
Edmond Pruteanu