Reputation: 13378
What is a better way than this:
X = %w(a b c)
Y = %w()
X.each do |x|
Y << "good_" + x
end
Thanks.
Upvotes: 0
Views: 56
Reputation:
to have them both defined on same line:
y = ( x = %w[a b c] ).map { |i| 'good_%s' % i }
y
=> ["good_a", "good_b", "good_c"]
x
=> ["a", "b", "c"]
Upvotes: 1
Reputation: 874
collect method on array will do
Y = X.collect{|e|'good_'+e}
OR
directly
Y = %w(a b c).collect{|e|'good_'+e}
Upvotes: 3