Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/solano/util.rb
Instance Method Summary collapse
Instance Method Details
#sanitize(encoding = "UTF-8") ⇒ Object
7 8 9 10 11 12 |
# File 'lib/solano/util.rb', line 7 def sanitize(encoding="UTF-8") opts = {:invalid => :replace, :undef => :replace} d = self.dup d.force_encoding(encoding).valid_encoding? ? d : d.force_encoding("BINARY").encode(encoding, opts) end |
#sanitize!(encoding = "UTF-8") ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/solano/util.rb', line 14 def sanitize!(encoding="UTF-8") opts = {:invalid => :replace, :undef => :replace} unless self.force_encoding(encoding).valid_encoding? self.force_encoding("BINARY") self.encode!(encoding, opts) end end |