Sha256: 564d35ea9a56f3890e5fe9e56eb7c6b3304d0ae3ee817bb852157dadad101314
Contents?: true
Size: 727 Bytes
Versions: 1
Compression:
Stored size: 727 Bytes
Contents
class String # This replaces Active Support's +String#last+, but it returns an # empty string when given a negative +limit+ argument, whereas Active # Support's +String#last+ removes +limit.abs+ characters from the # beginning of the string. Returning an empty string makes more sense # if you interpret +last+ as "keep upto +limit+ characters." At most, # a negative +limit+ should *keep* that many characters from the # beginning of the string, rather than *remove* that many characters # (but returning an empty string is a good conservative choice). Also # see +String#first+. # # This method is also faster. def last(limit = 1) limit < 0 ? '' : (self[-limit, limit] || self.dup) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
casual_support-2.0.0 | lib/casual_support/string/last.rb |