Ternary operation- takes 3 arguments; boolean, expression to determine if boolean is true + one to determine falseness
syntax = boolean? Do this if true(Evaluate this if true):Do this if false(Evaluate this if false)
Only requires 1 puts
statement at boolean part.
||
- used to only assign a variable which hasn't been assigned. nil
is ruby for nothing.
Ruby's method will return the result of the last evaluated expression unlike python where you have to explicitly state the evaluation. No need for return
Short circuit evaluation
Better tools to handle repetitive tasks in ruby than for
loops. To evaluate a specific number of times use .times
method. To repeat an action for every element in a collection use .each
method.
Single blocks are great for short/concise operations where multi line blocks using do
and end
are more practical for longer/more complex operations.
Top comments (0)