Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/string-ext.rb
Instance Method Summary collapse
-
#interpolate(values_hash = {}, options = {}) ⇒ Object
matches and replaces placeholders in form of %foo or %<foo>.
-
#to_boolean ⇒ Object
converts string to either TrueClass or FalseClass.
-
#to_params ⇒ Object
returns a hash like params containing all the “get” params from a given url Ex: ‘wiki.rego.co.il/doku.php?id=development:horizon3:plugins:core_extensions:start&do=edit&rev=’.to_params => :do=>‘edit’, :rev=>nil.
Instance Method Details
#interpolate(values_hash = {}, options = {}) ⇒ Object
matches and replaces placeholders in form of %foo or %<foo>
33 34 35 |
# File 'lib/string-ext.rb', line 33 def interpolate(values_hash = {}, = {}) StringInterpolation.interpolate(self, values_hash, ) end |
#to_boolean ⇒ Object
converts string to either TrueClass or FalseClass. If converion can’t be made, returns nil
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/string-ext.rb', line 21 def to_boolean s = self.downcase.strip if s == 'true' true elsif s == 'false' false else nil end end |
#to_params ⇒ Object
returns a hash like params containing all the “get” params from a given url Ex:
'http://wiki.rego.co.il/doku.php?id=development:horizon3:plugins:core_extensions:start&do=edit&rev='.to_params
=> {:id=>'development:horizon3:plugins:core_extensions:start', :do=>'edit', :rev=>nil}
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/string-ext.rb', line 7 def to_params hash = {} params=self.split("?") if params.size > 1 params=params[1].split("&") params=params.collect{|param| param.split("=")} params.each do |param| hash[param[0].to_sym]=param[1] end end hash end |