Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/mxfinfo/string.rb
Instance Method Summary collapse
-
#shell_escape_double_quotes ⇒ Object
returns the string enclosed in double quotes.
-
#underscore ⇒ Object
stolen from active_support/inflector TODO require “active_support/core_ext/string/inflections” when 3.0 is released.
Instance Method Details
#shell_escape_double_quotes ⇒ Object
returns the string enclosed in double quotes. all characters in the string that could be harmful will be escaped.
e.g. ‘test’.shell_escape_double_quotes # => “test” ‘$\’“‘’.shell_escape_double_quotes # => ”$\‘"`“
This should work in al POSIX compatible shells.
see: www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_02_03
12 13 14 |
# File 'lib/mxfinfo/string.rb', line 12 def shell_escape_double_quotes '"'+gsub(/\\|"|\$|`/, '\\\\\0')+'"' end |
#underscore ⇒ Object
stolen from active_support/inflector TODO require “active_support/core_ext/string/inflections” when 3.0 is released
18 19 20 21 22 23 24 |
# File 'lib/mxfinfo/string.rb', line 18 def underscore gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end |