Class: Forgery::Extensions::String

Inherits:
String
  • Object
show all
Defined in:
lib/forgery/extensions/string.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) camelize(first_letter = :upper)

Ripped right out of rails



14
15
16
17
18
19
20
21
# File 'lib/forgery/extensions/string.rb', line 14

def camelize(first_letter = :upper)
  case first_letter
  when :upper
    to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
  when :lower
    first.downcase + camelize(self)[1..-1]
  end
end

- (Object) constantize



24
25
26
27
28
29
30
31
32
33
# File 'lib/forgery/extensions/string.rb', line 24

def constantize
  names = self.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

- (Object) to_numbers(replace = '#')



9
10
11
# File 'lib/forgery/extensions/string.rb', line 9

def to_numbers(replace='#')
  gsub(/#{replace}/){ Kernel.rand(10) }
end

- (Object) unextend



5
6
7
# File 'lib/forgery/extensions/string.rb', line 5

def unextend
  to_s
end