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 encodings
puts "#{Encoding::UTF_8.dummy?}" # false
puts "#{Encoding::UTF_7.dummy?}" # true
puts "#{Encoding::UTF_16.dummy?}" # true
puts "#{Encoding::ISO_8859_1.dummy?}" # false
puts "#{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.
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources