Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
What is a better way than this:
X = %w(a b c) Y = %w() X.each do |x| Y << "good_" + x end
Thanks.
%w(a b c).map{|x| "good_#{x}"}
Add a comment
collect method on array will do
Y = X.collect{|e|'good_'+e}
OR
directly
Y = %w(a b c).collect{|e|'good_'+e}
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"]
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.