Array String Ruby

[Solved] Array String Ruby | Ruby - Code Explorer | yomemimo.com
Question : array string ruby

Answered by : edmond-hui

# to turn an array into a string in ruby you can use join or to_s
array = [1,2,3,4,5]
array.to_s # outputs "[1,2,3,4,5]"
array.join('') # outputs "12345"

Source : | Last Update : Sun, 01 Nov 20

Question : ruby array of strings

Answered by : mysterious-mantis-2t9yeiqzzhwz

# Array of symbols
%i[address city state post_code country]
=> [:address, :city, :state, :post_code, :country]
# Array of strings %w[address city state postal country]
=> ["address", "city", "state", "postal", "country"]
# Array of interpolated symbols
postal_label = 'zip'
%I[address city state #{postal_label} country]
=> [:address, :city, :state, :zip, :country]
# Array of interpolated strings
%W[address city state #{postal_label} country]
=> ["address", "city", "state", "zip", "country"]
# Instead of %i[] you may use %i{} or %i() or %i!!

Source : | Last Update : Mon, 19 Sep 22

Answers related to array string ruby

Code Explorer Popular Question For Ruby