Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/databasedotcom/core_extensions/string_extensions.rb

Overview

This extends String to add the resourcerize method.

Instance Method Summary collapse

Instance Method Details

#constantizeObject



9
10
11
12
13
14
# File 'lib/databasedotcom/core_extensions/string_extensions.rb', line 9

def constantize
  unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ self
    raise NameError, "#{self.inspect} is not a valid constant name!"
  end
  Object.module_eval("::#{$1}", __FILE__, __LINE__)
end

#resourcerizeObject

Dasherizes and downcases a camelcased string. Used for Feed types.



5
6
7
# File 'lib/databasedotcom/core_extensions/string_extensions.rb', line 5

def resourcerize
  self.gsub(/([a-z])([A-Z])/, '\1-\2').downcase
end