Module: RestfulError::Inflector
- Defined in:
- lib/restful_error/inflector.rb
Class Method Summary collapse
Class Method Details
.camelize(word_) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/restful_error/inflector.rb', line 18 def camelize(word_) return word_.camelize if word_.respond_to?(:camelize) word = word_.dup word.sub!(/^[a-z\d]*/) { ::Regexp.last_match(0).capitalize } word.gsub!(%r{(?:_|(/))([a-z\d]*)}) { "#{Regexp.last_match(1)}#{Regexp.last_match(2).capitalize}" } word.gsub!("/", "::") word end |
.underscore(word_) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/restful_error/inflector.rb', line 7 def underscore(word_) return word_.underscore if word_.respond_to?(:underscore) word = word_.dup word.gsub!("::", "/") word.gsub!(/(?<=[A-Z])(?=[A-Z][a-z])|(?<=[a-z\d])(?=[A-Z])/, "_") word.tr!("-", "_") word.downcase! word end |