What is the `dummy?` property for an encoding in Ruby?
Overview
The dummy? property of an encoding in Ruby returns true if an encoding is a dummy. An encoding is a dummy if the character handling is not properly implemented.
Syntax
Encoding::encoding.dummy?
Return value
A Boolean value is returned. If the encoding is dummy, true is returned. Otherwise, false is returned.
Code
# check for some dummy encodingsputs "#{Encoding::UTF_8.dummy?}" # falseputs "#{Encoding::UTF_7.dummy?}" # trueputs "#{Encoding::UTF_16.dummy?}" # trueputs "#{Encoding::ISO_8859_1.dummy?}" # falseputs "#{Encoding::Windows_1250.dummy?}" # false
Explanation
- Line 2-6: We check if some encodings are dummies using the
dummy?property of an encoding instance. Then, we print the result to the console.