0
的數組我有以下數組不可變的方法來改變屬性的對象
Bot = Struct.new(:name, :age)
bots = %w(foo bar baz).map do |name|
Bot.new(name, rand(10))
end
p bots
[ #<struct Bot name="foo", age=3>,
#<struct Bot name="bar", age=8>,
#<struct Bot name="baz", age=0> ]
我想從bots
,其中age
屬性轉換to_s
得到一個新的數組,但我不想改變數組中的真實物體bots
。 我該怎麼做?