Class: Forgery::Extensions::String
- Inherits:
-
String
- Object
- String
- Forgery::Extensions::String
- Defined in:
- lib/forgery/extensions/string.rb
Instance Method Summary collapse
-
#camelize(first_letter = :upper) ⇒ Object
Ripped right out of rails.
- #constantize ⇒ Object
- #to_numbers(replace = '#') ⇒ Object
- #unextend ⇒ Object
Instance Method Details
#camelize(first_letter = :upper) ⇒ Object
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 |
#constantize ⇒ Object
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 |
#to_numbers(replace = '#') ⇒ Object
9 10 11 |
# File 'lib/forgery/extensions/string.rb', line 9 def to_numbers(replace='#') gsub(/#{replace}/){ Kernel.rand(10) } end |
#unextend ⇒ Object
5 6 7 |
# File 'lib/forgery/extensions/string.rb', line 5 def unextend to_s end |