class RubyWordSort
def initialize(fileName)
@dataFile = File.new(fileName)
@words = Array.new
end
def sortedWorts
if (@words.length == 0)
@dataFile.each_line{ |line| line.split(' ').each{ |word| @words << word}}
@words = @words.sort{ |w,w1| w.upcase <=> w1.upcase }
end
@words
end
end
Wednesday, May 20, 2009
JavaOne Talk: Ruby Word Sort
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment