Array.which_long? -- 剛出爐的函式
class Array
def which_long?
# Version 1.0
# Coded by CFC <>
# PLEASE DO NOT REMOVE THE COMMENT OF THIS FUNCTION, THANKS A LOT.
# Usage:
# ['a', 'ab', 'abc' 1234].which_long?
# => 1234
self.size.times{|i| self[i]=self[i].to_s}
max, long = 0, String.new
self.each{|item| item.size > max ? (max = item.size; long = item) : next}
long
end
end
以上是原始碼,使用方式如下:
puts ['a', 'ab', 'abc', 1234].which_long?
=> 1234
授權還沒定,不過大家還是可以拿去使用:P
請不要拿掉註解.. 謝謝
沒有留言:
張貼留言