Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/corefoundation/extensions.rb
Overview
Ruby String class
Instance Method Summary collapse
-
#binary!(bin = true) ⇒ Object
On ruby 1.8.7 sets or clears the flag used by #binary?.
- #binary? ⇒ Boolean
-
#to_cf ⇒ CF::String, CF::Data
Returns a CF::String or CF::Data representing the string.
-
#to_cf_data ⇒ CF::Data
Returns a CF::Data representing the string.
-
#to_cf_string ⇒ CF::String
Returns a CF::String representing the string.
Instance Method Details
#binary!(bin = true) ⇒ Object
Note:
There is no advantage to using this over the standard encoding methods unless you wish to retain 1.8.7 compatibility
On ruby 1.8.7 sets or clears the flag used by #binary?. On ruby 1.9 the string’s encoding is forced.
100 101 102 103 104 105 106 107 108 |
# File 'lib/corefoundation/extensions.rb', line 100 def binary!(bin=true) if bin == true self.force_encoding Encoding::ASCII_8BIT else # default to utf-8 self.force_encoding( (bin == false) ? "UTF-8" : bin) end self end |
#binary? ⇒ Boolean
72 73 74 |
# File 'lib/corefoundation/extensions.rb', line 72 def binary? encoding == Encoding::ASCII_8BIT end |
#to_cf ⇒ CF::String, CF::Data
Returns a CF::String or CF::Data representing the string. If #binary? returns true a CF::Data is returned, if not a CF::String is returned
If you want a CF::Data with the contents of a non binary string, use #to_cf_data
54 55 56 |
# File 'lib/corefoundation/extensions.rb', line 54 def to_cf self.binary? ? self.to_cf_data : self.to_cf_string end |
#to_cf_data ⇒ CF::Data
Returns a CF::Data representing the string
132 133 134 |
# File 'lib/corefoundation/extensions.rb', line 132 def to_cf_data CF::Data.from_string self end |
#to_cf_string ⇒ CF::String
Returns a CF::String representing the string
126 127 128 |
# File 'lib/corefoundation/extensions.rb', line 126 def to_cf_string CF::String.from_string self end |