Complete the code to call the parent method from the child class.
class Parent def greet puts "Hello from Parent" end end class Child < Parent def greet [1] end end Child.new.greet
In Ruby, super calls the same method from the parent class.
Complete the code to call the parent method with arguments.
class Parent def greet(name) puts "Hello, #{name} from Parent" end end class Child < Parent def greet(name) [1] end end Child.new.greet("Alice")
super without arguments passes all arguments automatically, but here explicit passing is clearer.super() calls the parent method without arguments, causing errors.super.greet(name) is invalid syntax.Use super(name) to pass the argument to the parent method.
Fix the error in calling the parent method inside a module included in a class.
module Mixin def greet [1] end end class Parent def greet puts "Hello from Parent" end end class Child < Parent include Mixin end Child.new.greet
Inside a module method, super calls the next method in the lookup chain, here the parent class method.
Fill the blank to call the parent method and add extra behavior.
class Parent def greet puts "Hello from Parent" end end class Child < Parent def greet [1] puts "And hello from Child" end end Child.new.greet
Use super or super() to call the parent method before adding child behavior.
Fill the blank to override a method, call the parent method with arguments, and add extra output.
class Parent def greet(name) puts "Hello, #{name} from Parent" end end class Child < Parent def greet(name) [1] puts "And hello from Child to #{name}" end end Child.new.greet("Bob")
self.greet(name) causes infinite recursion.super() without arguments causes errors here.Use super(name) to call the parent method with argument.
