Zen of Ruby
Felix Imbanga
Posted on March 14, 2024
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.
Posted on March 14, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 29, 2024