Complete the code to check if the variable is exactly an Integer using .class.
num = 10 puts num.class == [1]
The .class method returns the exact class of an object. To check if num is an Integer, compare num.class with Integer.
Complete the code to check if the variable is a kind of Numeric using .is_a?.
value = 3.14 puts value.[1](Numeric)
instance_of? which checks only exact class, not subclasses.The .is_a? method checks if an object is an instance of a class or its subclass. Here, it checks if value is a kind of Numeric.
Fix the error in the code to correctly check if 'text' is a String using .class.
text = "hello" if text.class [1] String puts "It's a string!" end
= instead of double equals == for comparison.The code uses a single equals sign = which is assignment, not comparison. To compare classes, use ==.
Fill both blanks to create a hash of words and their lengths, including only words longer than 3 characters.
words = ["cat", "house", "dog", "elephant"] lengths = {word: word.[1] for word in words if word.[1] [2] 3}
word.length is valid but not in options; using < instead of >.Use word.size to get the length of the word. The condition word > 3 is invalid, so use word.size > 3 to filter words longer than 3 characters.
Fill all three blanks to create a hash with uppercase words as keys and their lengths as values, including only words with length greater than 4.
words = ["apple", "bat", "carrot", "dog"] result = { [1]: [2] for w in words if [2] [3] 4 }
w.downcase instead of w.upcase for keys; using < instead of >.Use w.upcase for keys to get uppercase words, w.length for values to get word length, and > to filter words longer than 4 characters.