Ruby - Modules and Mixins
What will be the output of the following Ruby code?
module MathTools
def self.square(x)
x * x
end
end
puts MathTools.square(4)module MathTools
def self.square(x)
x * x
end
end
puts MathTools.square(4)square is defined as a module method using self.square. It returns the square of the input.MathTools.square(4) returns 4 * 4 = 16, which is printed.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions