neocities/ext/string.rb

27 lines
410 B
Ruby
Raw Permalink Normal View History

class String
2014-07-03 14:03:35 -05:00
def shorten(length, usedots=true)
if usedots
return self if self.length < length
"#{self[0..length-3]}..."
else
self[0..length]
end
end
2014-11-20 04:44:44 -08:00
def unindent
gsub /^#{scan(/^\s*/).min_by{|l|l.length}}/, ""
end
def blank?
return true if self == ''
false
end
2024-02-17 10:27:02 -06:00
def not_an_integer?
Integer(self)
false
rescue ArgumentError
true
end
end