Class: CoreExt

Inherits:
Object
  • Object
show all
Defined in:
lib/checker/core_ext.rb

Class Method Summary collapse

Class Method Details

.classify(underscored_word) ⇒ Object



13
14
15
16
17
18
# File 'lib/checker/core_ext.rb', line 13

def self.classify(underscored_word)
  words = underscored_word.split("_")
  words.each do |word|
    word.capitalize!
  end.join("")
end

.constantize(camel_cased_word) ⇒ Object



2
3
4
5
6
7
8
9
10
11
# File 'lib/checker/core_ext.rb', line 2

def self.constantize(camel_cased_word)
  names = camel_cased_word.split('::')
  names.shift if names.empty? || names.first.empty?

  constant = Object
  names.each do |name|
    constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
  end
  constant
end

.underscore(camel_cased_word) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/checker/core_ext.rb', line 20

def self.underscore(camel_cased_word)
  word = camel_cased_word.to_s.dup
  word.gsub!(/::/, '/')
  word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
  word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
  word.tr!("-", "_")
  word.downcase!
  word
end