From: Harry Date: 2007-04-29T23:14:20+09:00 Subject: Re: Array.which_long? ( I coded an extension for Array ) On 4/29/07, Billy Hsu wrote: > Hi, I'm CFC > I'm new at here. > Nice to meet you:) > > I just coded an extension for Array. > It will return the longest element of an array. > Source: > > class Array > def which_long? > # Version 1.0 > # Coded by CFC < zusocfc @ gmail . com > > # PLEASE DO NOT REMOVE THE COMMENT OF THIS FUNCTION, THANKS A LOT. > # Usage: > # ['a', 'ab', 'abc' 1234].which_long? > # => 1234 > max, long, self_cpy = 0, "", [] > self.size.times{|i| self_cpy << self[i].to_s} > self_cpy.each{|item| (max = item.size; long = item) if item.size > max } > long > end > end > > Usage: > puts [1, 23, '456'].which_long? > => 456 > > CFC -- > Hi, Welcome. You may be interested in this. I did not study your code well but I think it is doing something similar. p [1, 23, '456'].max {|x,y| x.to_s.size <=> y.to_s.size} Harry -- http://www.kakueki.com/ruby/list.html A Look into Japanese Ruby List in English