Most the time in Ruby parentheses are optional for parameters in method calls. Here is one case where you can expect the unexpected.

class Course
  def track
    puts 'masters'
  end
end
 
class Elective < Course
  def track(type)
    super
    puts type
  end
end
 
Elective.new.track('art') 
#=> ArgumentError: wrong number of arguments (1 for 0)

But…

class Course
  def track
    puts 'masters'
  end
end
 
class Elective < Course
  def track(type)
    super()
    puts type
  end
end
 
Elective.new.track('art') 
#=> masters

:)

Leave a Reply

Your email address will not be published. Required fields are marked *