Passing Arguments to the Superclass

Parentheses matter when calling the superclass! If the argument list is empty and no parentheses are used, all arguments are passed to the superclass. But if the argument list is empty and parentheses are used, no arguments are passed to the superclass:

super_args.rb

# This passes a, b, c to the superclass
def initialize( a, b, c, d, e, f )
   super( a, b, c )
end

# This passes a, b, c to the superclass
def initialize( a, b, c )
   super
end

# This passes no arguments to the superclass
def initialize( a, b, c)
   super()
end

Note

To gain a better understanding of the use of super, see Digging Deeper in Digging Deeper.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.105.215