Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/core_refinements/String/to_human.rb

Instance Method Summary collapse

Instance Method Details

#to_humanObject

take a CamelCase or under_scored string and convert it to a human readable string (useful for output).



6
7
8
9
10
# File 'lib/core_refinements/String/to_human.rb', line 6

def to_human
  return self.split("_").map {|word| word[0] + word[1..-1]}.join(" ") if self.include?("_")

  return self.split(/(?=[A-Z])/).join(" ").downcase
end