module Slacker::StringHelper

Public Class Methods

camelize(lower_case_and_underscored_word) click to toggle source
# File lib/slacker/string_helper.rb, line 4
def camelize(lower_case_and_underscored_word)
  lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
end
constantize(camel_cased_word) click to toggle source
# File lib/slacker/string_helper.rb, line 8
def constantize(camel_cased_word)
  unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ camel_cased_word
    raise NameError, "#{camel_cased_word.inspect} is not a valid constant name!"
  end

  Object.module_eval("::#{$1}", __FILE__, __LINE__)
end