Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/csv-import-analyzer/helpers/string_class_extensions.rb
Instance Method Summary collapse
-
#substr_count(needle) ⇒ Object
Monkey patch string class to find the count of needle in haystack haystack is self => string in itself needle could be anything E.g.
Instance Method Details
#substr_count(needle) ⇒ Object
Monkey patch string class to find the count of needle in haystack haystack is self => string in itself needle could be anything E.g. “hello, how, are, you”.substr_count(“,”) => 3
10 11 12 13 |
# File 'lib/csv-import-analyzer/helpers/string_class_extensions.rb', line 10 def substr_count(needle) needle = "\\#{needle}" if(needle == '|') # To escape inside regex self.scan(/(#{needle})/).size end |