ruby 关于截断truncate和单复数pluralize的使用分享
truncate:
truncate("Once upon a time in a world far far away") # => "Once upon a time in a world..." truncate("Once upon a time in a world far far away", :length => 17) # => "Once upon a ti..." truncate("Once upon a time in a world far far away", :length => 17, :separator => ' ') # => "Once upon a..." truncate("And they found that many people were sleeping better.", :length => 25, :omission => '... (continued)') # => "And they f... (continued)" truncate("<p>Once upon a time in a world far far away</p>") # => "<p>Once upon a time in a wo..."
pluralize:
pluralize(1, 'person') # => 1 person pluralize(2, 'person') # => 2 people pluralize(3, 'person', 'users') # => 3 users pluralize(0, 'person') # => 0 people