From: Todd Benson Date: 2008-01-24T04:25:38+09:00 Subject: Re: Alphabetizing On Jan 22, 2008 11:22 PM, Zenki Nine wrote: > Hi, > > I'm trying to write a code where I can alphabetize the players last_name > with its batting average > > players_avg= << PLAYERS > Barry Bonds, .293 > Mike Gallego, .263 > Ichiro Suzuki, .396 > Tony Gwynn, .403 > Alex Rodriguez, .310 > PLAYERS > > players = presidents_avg.strip.collect { |players| players.strip > }.compact > > #initialiating players_by_last_name with an empty array > players_by_last_name = [] This isn't the best solution ... just there for s**ts and giggles... irb(main):002:0> players = players_avg.split("\n").sort_by {|i| (i.scan /\w*/)[2]} Todd