Joined July 2013
·

Nick Gorbikoff

birica
·
Chicago
·
·

Posted to Array#extract_if over 1 year ago

You have a few typos in your example. If this was your goal - "Here's one : you have a list of random links but you want wikipedia to always appear first." , then your example needs to be rewritten like this.

@links = [ 'random.com/bla','...', 'wikipedia.com/bla',' ...', 'random2.com']
@wiki= @links.extract_if {|link| link.match(/wikipedia.com/) }
@links.unshift(@wiki)
@links.join(" - ")

This can be futher optimized of course

Achievements
39 Karma
0 Total ProTip Views