How to: Array to Sentence in Ruby
The Ruby programming language can store data as a select number of types, such as a hash, an array, an integer, a float or a string. An array is a list of items within brackets, such as ["the", "cow", "jumped", "over", "the", "moon"], which is an array containing six words. You can search or sort the items in an array as needed. A string is a single block of text, similar to a sentence, though it can contain multiple sentences. You can convert an array into a string with a single Ruby command.
Instructions
-
-
1
Open the Command Prompt. Type "irb" at the command line to launch the Interactive Ruby Console.
-
2
Assign your array to a variable, such as "mylist":
mylist = ["the", "cow", "jumped", "over", "the", "moon"]
-
-
3
Type "mylist.inspect" (without quotation marks) to convert your array to a string. Replace "mylist" with the name of your array. You now have a string version of your array.
-
1