Class: String

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

Instance Method Summary collapse

Instance Method Details

#constantizeObject

copied from resque



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/qmin/core_ext/string.rb', line 12

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

  constant = Object
  names.each do |name|
    args = Module.method(:const_get).arity != 1 ? [false] : []

    if constant.const_defined?(name, *args)
      constant = constant.const_get(name)
    else
      constant = constant.const_missing(name)
    end
  end
  constant
end

#to_queue_nameObject



30
31
32
# File 'lib/qmin/core_ext/string.rb', line 30

def to_queue_name
  gsub('::','').underscore
end

#underscoreObject



3
4
5
6
7
8
9
# File 'lib/qmin/core_ext/string.rb', line 3

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