Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/core_ext/string.rb
Instance Method Summary collapse
-
#camelize ⇒ String
Find words, capitalize and join.
-
#no_erb ⇒ String
Remove the erb extension if there is one.
-
#substitute_env_vars ⇒ String
Replace dollar-curly braces, with the value of environment variable.
-
#underscoreize ⇒ String
Find words breaks and insert underscores.
Instance Method Details
#camelize ⇒ String
Find words, capitalize and join
5 6 7 |
# File 'lib/core_ext/string.rb', line 5 def camelize self.split(/[^a-z0-9]/i).map{|w| w.capitalize}.join end |
#no_erb ⇒ String
Remove the erb extension if there is one
26 27 28 |
# File 'lib/core_ext/string.rb', line 26 def no_erb self.sub(/\.erb$/,'') end |
#substitute_env_vars ⇒ String
Replace dollar-curly braces, with the value of environment variable
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/core_ext/string.rb', line 34 def substitute_env_vars str = String.new(self) str.scan(/\$\{([A-Z][A-Z,0-9,_]*)\}/).uniq.each do |m| begin str.gsub!("${#{m[0]}}", ENV[m[0]]) rescue $stderr.puts "problem with enviroment variable #{m[0]}." end end str end |
#underscoreize ⇒ String
Find words breaks and insert underscores
13 14 15 16 17 18 19 |
# File 'lib/core_ext/string.rb', line 13 def underscoreize self.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end |