-1
的目的是創造一個字符串並且在紅寶石整數序列,即,hello0, hello1, hello2
。 hello
代表一個字符串,數字:1,2 and 3
是整數。
嘗試
seq=(0..3).to_a
回報
0
,1
,2
,3
問題
如何在Ruby中創建一個字符串和整數序列?
的目的是創造一個字符串並且在紅寶石整數序列,即,hello0, hello1, hello2
。 hello
代表一個字符串,數字:1,2 and 3
是整數。
嘗試
seq=(0..3).to_a
回報
0
,1
,2
,3
問題
如何在Ruby中創建一個字符串和整數序列?
目的是在Ruby來創建文本和整數序列,即,
hello0, hello1, hello2
可以一個塊傳遞到Array::new
:
Array.new(3) { |i| "hello#{i}" }
#=> ["hello0", "hello1", "hello2"]
(0..3).to_a.map {|e| "hello#{e}" }
喜歡這個? '[ 「你好」]的產物((0..3).to_a).MAP(&:加入)。#=> [ 「hello0」, 「hello1」, 「hello2」, 「hello3」]' – engineersmnky 2015-02-23 16:20:13
@engineersmnky作品。請添加它作爲答案。 – 030 2015-02-23 16:25:10
你的問題是什麼? – sawa 2015-02-23 16:36:02