You can use the range syntax [1..4] in Ruby to generate an array.
Here is an example:
main.rb39 chars3 lines
Output:
main.rb13 chars2 lines
In the above example, we create a range from 1 to 4 using the syntax (1..4). Then, we convert the range to an array using the to_a
method. Finally, we print the array using inspect
. The resulting array is [1, 2, 3, 4].
gistlibby LogSnag