Module: Useful::RubyExtensions::String::InstanceMethods

Defined in:
lib/useful/ruby_extensions/string.rb

Instance Method Summary collapse

Instance Method Details

#cgi_escapeObject



61
62
63
# File 'lib/useful/ruby_extensions/string.rb', line 61

def cgi_escape
  self.class.cgi_escape(self)
end

#cgi_escape!Object



65
66
67
# File 'lib/useful/ruby_extensions/string.rb', line 65

def cgi_escape!
  self.replace(self.class.cgi_escape(self))
end

#empty!Object

will destructively empty out a string, making its value “”



57
58
59
# File 'lib/useful/ruby_extensions/string.rb', line 57

def empty!
  self.replace("")
end

#from_currency_to_fObject



85
86
87
# File 'lib/useful/ruby_extensions/string.rb', line 85

def from_currency_to_f
  self.gsub(/[^0-9.-]/,'').to_f
end

#hsub(hash) ⇒ Object

returns a new string, with hash values sub’d in where hash keys exist in original string



48
49
50
# File 'lib/useful/ruby_extensions/string.rb', line 48

def hsub(hash)
  self.class.hsub(self.dup, hash)
end

#hsub!(hash) ⇒ Object

substitutes the keys in hash that exist in the string, with values of hash



52
53
54
# File 'lib/useful/ruby_extensions/string.rb', line 52

def hsub!(hash)
  self.class.hsub(self, hash)
end

#match?(pattern) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/useful/ruby_extensions/string.rb', line 69

def match?(pattern)
  self.class.match?(self, pattern)
end

#show_regexp(re) ⇒ Object



77
78
79
# File 'lib/useful/ruby_extensions/string.rb', line 77

def show_regexp(re)
  self.class.show_regexp(self, re)
end

#to_booleanObject



81
82
83
# File 'lib/useful/ruby_extensions/string.rb', line 81

def to_boolean
  self =~ /^(false|0)$/i ? false : true
end

#to_time_atObject



89
90
91
# File 'lib/useful/ruby_extensions/string.rb', line 89

def to_time_at
  self.to_i.to_time_at
end

#valid_email?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/useful/ruby_extensions/string.rb', line 73

def valid_email?
  self.class.valid_email?(self)
end