Ruby Lambda Operator

A lambda is a way to define a block and its parameter with special syntax.

greet1 = -> { puts “Hello world.” }

greet2 = lambda { puts “Hello world !” }

greet1.call

greet2.call

greet_with_param = ->(name) { puts “Hello #{name}!” }

greet_with_param.call(“Joni”)

Optimize linux battery life

Ubuntu/Debian : sudo apt install tlp

to start it : sudo tlp start

to show stat : sudo tlp stat

Long time no see wordpress ! been busy lately.

Ruby spaceship operator <=>

The spaceship operator is general comparison operator. The <=> operator compares 2 values and returning -1, 0, or 1 depending on whether the first value is less than, equal, or greater than the second.

Example in irb.

This operator is used on ruby range operation , objects must implement <=> and succ method to perform range operation. Lets test the a numeric value for these methods.

Keep learning ruby on 2021.