ShardsOfPower/primitive_adds.rb

49 lines
816 B
Ruby
Raw Normal View History

2019-05-27 15:02:07 -04:00
class String
2019-05-29 03:39:21 -04:00
PUNCTUATION_MARKS = [".", "!", "?"]
2019-05-27 15:02:07 -04:00
def titleize
gsub(/\w+/i) do |match|
ret = match.downcase
ret[0] = ret[0].upcase
ret
end
end
def titleize!
replace titleize
end
2019-05-29 03:39:21 -04:00
def punctuated?
PUNCTUATION_MARKS.include?(self[-1])
end
def unpunctuated?
!punctuated?
end
2019-05-27 15:02:07 -04:00
end
class Integer
def to_dots
"" * self
end
2019-05-28 01:53:25 -04:00
end
class Array
def to_list(separator: nil)
2019-05-29 03:39:21 -04:00
separator = "and" if separator.nil?
2019-05-28 01:53:25 -04:00
if self.length == 0
nil
elsif self.length == 1
self.first
elsif self.length == 2
"#{self.first} #{separator} #{self.last}"
else
ret = clone
2019-05-29 03:39:21 -04:00
ret[ret.length - 1] = "#{separator} #{ret[ret.length - 1]}"
2019-05-28 01:53:25 -04:00
ret.join(", ")
end
end
def to_arcanum_with_dots
"#{self[0].to_s.titleize} #{self[1].to_dots}"
end
2019-05-27 15:02:07 -04:00
end