Module: Juke::Ext::Utils

Extended by:
Utils
Included in:
Utils
Defined in:
lib/juke/ext/utils.rb

Instance Method Summary collapse

Instance Method Details

#camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/juke/ext/utils.rb', line 8

def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
  if first_letter_in_uppercase
    lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
  else
    lower_case_and_underscored_word.first + camelize(lower_case_and_underscored_word)[1..-1]
  end
end

#constantize(camel_cased_word) ⇒ Object



16
17
18
19
20
21
# File 'lib/juke/ext/utils.rb', line 16

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