Class: String

Inherits:
Object show all
Defined in:
lib/swxruby/core_extensions.rb

Instance Method Summary collapse

Instance Method Details

#begins_with?(string) ⇒ Boolean

Returns:

  • (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

Returns:

  • (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_asciiObject



27
28
29
30
# File 'lib/swxruby/core_extensions.rb', line 27

def hex_to_ascii
	hex = self.gsub(' ', '')
	[hex].pack('H*')
end

#underscoreObject

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