Module: Useful::RubyExtensions::String
- Included in:
- String
- Defined in:
- lib/useful/ruby_extensions/string.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#hsub(hash) ⇒ Object
returns a new string, with hash values sub’d in where hash keys exist in original string.
-
#hsub!(hash) ⇒ Object
substitutes the keys in hash that exist in the string, with values of hash.
- #match?(pattern) ⇒ Boolean
- #show_regexp(re) ⇒ Object
- #to_boolean ⇒ Object
Class Method Details
.included(klass) ⇒ Object
6 7 8 |
# File 'lib/useful/ruby_extensions/string.rb', line 6 def self.included(klass) klass.extend(ClassMethods) if klass.kind_of?(Class) end |
Instance Method Details
#hsub(hash) ⇒ Object
returns a new string, with hash values sub’d in where hash keys exist in original string
21 22 23 |
# File 'lib/useful/ruby_extensions/string.rb', line 21 def hsub(hash) self.class.hsub(self.clone, hash) end |
#hsub!(hash) ⇒ Object
substitutes the keys in hash that exist in the string, with values of hash
25 26 27 |
# File 'lib/useful/ruby_extensions/string.rb', line 25 def hsub!(hash) self.class.hsub(self, hash) end |
#match?(pattern) ⇒ Boolean
29 30 31 |
# File 'lib/useful/ruby_extensions/string.rb', line 29 def match?(pattern) !self.match(pattern).nil? end |
#show_regexp(re) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/useful/ruby_extensions/string.rb', line 33 def show_regexp(re) if self =~ re "#{$`}<<#{$&}>>#{$'}" else "no match" end end |
#to_boolean ⇒ Object
41 42 43 |
# File 'lib/useful/ruby_extensions/string.rb', line 41 def to_boolean self =~ /^(true|1)$/i ? true : false end |