In other programming languages this is known as a switch statement.
Ruby switch case assignment.
The components of a case statement in ruby.
It is used to match a single condition.
This is both for variables and objects but since strings floats and integers are actually objects in ruby you re always assigning objects.
Case as switch statement in ruby with parameter.
In programming languages a switch statement is a type of control mechanism used to check if the value of a variable or expression exists and what the program should do from that point.
As of ruby 1 6 2 if an assignment has one lvalue and multiple rvalues the rvalues are converted to an array and assigned to the lvalue.
In ruby it is implemented using the case argument.
It is similar to the case keyword in another programming languages.
There can be multiple when statements into a single case statement.
Case equality case subsumption or three equals operator.
In this post you will learn a few different use cases and how it all really works under the hood.
You can collapse and expand arrays using ruby s parallel assignment operator.
Parallel assignment in ruby.
If a multiple assignment contains more rvalues than lvalues the extra rvalues are ignored.
Assignment in ruby is done using the equal operator.
It takes the variables that will be used by when keyword.