Module: Q::Helpers

Included in:
Q
Defined in:
lib/q/helpers.rb

Instance Method Summary collapse

Instance Method Details

#camelize(term) ⇒ Object



3
4
5
6
7
8
# File 'lib/q/helpers.rb', line 3

def camelize(term)
  string = term.to_s
  string = string.sub(/^[a-z\d]*/) { $&.capitalize }
  string = string.gsub(/(?:_|(\/))([a-z\d]*)/i) { "#{$2.capitalize}" }.gsub('/', '::')
  string
end

#const_defined_on?(on, const) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/q/helpers.rb', line 17

def const_defined_on?(on, const)
  on.constants.include?(const.to_sym)
end

#proc_to_lambda(block = nil, &proc) ⇒ Object



21
22
23
# File 'lib/q/helpers.rb', line 21

def proc_to_lambda(block = nil, &proc)
  ::ProcToLambda.to_lambda(block || proc)
end

#underscore(term) ⇒ Object



10
11
12
13
14
15
# File 'lib/q/helpers.rb', line 10

def underscore(term)
  string = term.to_s
  string = string.sub(/^[a-z\d]*/) { "#{$&.downcase}_" }
  string = string.gsub(/^_/, '')
  string
end