Class: String
Instance Method Summary collapse
- #begins_with?(string) ⇒ Boolean
- #concludes_with?(*strings) ⇒ Boolean
- #hex_to_ascii ⇒ Object
-
#underscore ⇒ Object
Taken from Rails’ Inflector module.
Instance Method Details
#begins_with?(string) ⇒ Boolean
19 20 21 |
# File 'lib/swxruby/core_extensions.rb', line 19 def begins_with?(string) self[0..string.length-1] == string end |
#concludes_with?(*strings) ⇒ Boolean
23 24 25 |
# File 'lib/swxruby/core_extensions.rb', line 23 def concludes_with?(*strings) strings.any? { |string| self[-(string.length)..-1] == string } end |
#hex_to_ascii ⇒ Object
27 28 29 30 |
# File 'lib/swxruby/core_extensions.rb', line 27 def hex_to_ascii hex = self.gsub(' ', '') [hex].pack('H*') end |
#underscore ⇒ Object
Taken from Rails’ Inflector module
33 34 35 36 37 38 39 |
# File 'lib/swxruby/core_extensions.rb', line 33 def underscore self.to_s.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end |