to truncate or not?

Jul 10
2008
# RoR source code:
# File vendor/rails/actionpack/lib/action_view/helpers/text_helper.rb, line 34
def truncate(text, length = 30, truncate_string = "...")
  if text.nil? then return end
  l = length - truncate_string.chars.length
  text.chars.length > length ? text.chars[0...l] + truncate_string : text
end
 
# My point of view:
def truncate(text, _length = 30, truncate_string = "...")
  text[0..(_length-1)] + truncate_string
end

Comments are closed.

Calendar

July 2008
M T W T F S S
« Jun   Aug »
 123456
78910111213
14151617181920
21222324252627
28293031  

Tags