In Ruby, you can use the Range
and join
methods to create the string 'abcdefghijklmnopqrstuvwxyz'
in a more concise way. Here's an example:
main.rb50 chars3 lines
Output:
main.rb27 chars2 lines
In the code snippet above:
('a'..'z')
creates a range from 'a'
to 'z'
.to_a
converts the range to an array.join('')
concatenates all the elements of the array, using an empty string ''
as the separator.puts
is used to print the resulting string.This way, you can create the desired string using a shortcut code in Ruby.
gistlibby LogSnag