39 lines
626 B
Ruby
39 lines
626 B
Ruby
class String
|
|
def titleize
|
|
gsub(/\w+/i) do |match|
|
|
ret = match.downcase
|
|
ret[0] = ret[0].upcase
|
|
ret
|
|
end
|
|
end
|
|
|
|
def titleize!
|
|
replace titleize
|
|
end
|
|
end
|
|
|
|
class Integer
|
|
def to_dots
|
|
"•" * self
|
|
end
|
|
end
|
|
|
|
class Array
|
|
def to_list(separator: nil)
|
|
if self.length == 0
|
|
nil
|
|
elsif self.length == 1
|
|
self.first
|
|
elsif self.length == 2
|
|
"#{self.first} #{separator} #{self.last}"
|
|
else
|
|
ret = clone
|
|
ret[ret.length - 1] = "#{separator ? separator : "and"} #{ret[ret.length - 1]}"
|
|
ret.join(", ")
|
|
end
|
|
end
|
|
|
|
def to_arcanum_with_dots
|
|
"#{self[0].to_s.titleize} #{self[1].to_dots}"
|
|
end
|
|
end |