lib/mack-facets/extensions/string.rb in mack-facets-0.8.1 vs lib/mack-facets/extensions/string.rb in mack-facets-0.8.2
- old
+ new
@@ -1,7 +1,6 @@
class String
- include Style
alias_instance_method :snakecase, :underscore
def /(other)
File.join(self, other.to_s)
@@ -76,9 +75,19 @@
n_middle.squeeze!("_")
x.gsub!(orig_middle, n_middle)
x.gsub!("_=", "=")
x
+ end
+
+ # Capitalizes the first word and turns underscores into spaces and strips _id.
+ # Like titleize, this is meant for creating pretty output.
+ #
+ # Examples
+ # "employee_salary" #=> "Employee salary"
+ # "author_id" #=> "Author"
+ def humanize
+ self.gsub(/_id$/, "").gsub(/_/, " ").capitalize
end
# Returns a constant of the string.
#
# Examples: