Can some analyse this piece of code

Hi Guys,

Stumbled upon this piece of code and would like to know what it does


1 Like


Iā€™m not a Ruby developper, but I challenched my self to understand this with my Javascript knowledge.

First, we need to explode this inline code.

first_part = (0...8)

second_part ={65.+(rand(25))}


The first part create an array of digits from 0 to 7.

The second part is a map that invokes block once for each element in the array.
In this case this will fill each element with 65.+(rand(25)).

65.+(rand(25)) is something like 65 added to a random number between 0 and 25.

So, the second_part array contains 8 elements with value between 65 and 90.

The lastpart is about to join this array in a single element.

['a', 'l', 'p', 'h', 'a'].join => 'alpha'
1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.