Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do you call the -> operator in Ruby?

Tags:

syntax

ruby

People also ask

What are operators in Ruby?

Ruby Arithmetic OperatorsAddition − Adds values on either side of the operator. Subtraction − Subtracts right hand operand from left hand operand. Multiplication − Multiplies values on either side of the operator. Division − Divides left hand operand by right hand operand.

What is the name of this operator === Ruby?

Triple Equals Operator (More Than Equality) Our last operator today is going to be about the triple equals operator ( === ). This one is also a method, and it appears even in places where you wouldn't expect it to. Ruby is calling the === method here on the class.

What does === mean in Ruby?

In Ruby, the === operator is used to test equality within a when clause of a case statement.

What do two colons mean in Ruby?

Double colon ( : ) operator is use to access the constants, class methods and instance methods defined within a class or module to anywhere outside the class or module.


In Ruby Programming Language ("Methods, Procs, Lambdas, and Closures"), a lambda defined using -> is called lambda literal.

succ = ->(x){ x+1 }
succ.call(2)

The code is equivalent to the following one.

succ = lambda { |x| x + 1 }
succ.call(2)

Informally, I have heard it being called stabby lambda or stabby literal.


=> == Hash Rocket

Separates keys from values in a hash map literal.


-> == Dash Rocket

Used to define a lambda literal in Ruby 1.9.X (without args) and Ruby 2.X (with args). The examples you give (->(x) { x * 2 } & lambda { |x| x * 2 }) are in fact equivalent.


Lambda rocket

I got that from this article. But first a google search for ruby lambda shorthand http://ruby-journal.com/becareful-with-space-in-lambda-hash-rocket-syntax-between-ruby-1-dot-9-and-2-dot-0/


->(x) { ... } is the same as lambda { |x| ... }. It creates a lambda. See Kernel#lambda A lambda is a type of proc, one that ensures the number of parameters passed to it is correct. See also Proc::new and Kernel#proc.