Learn Ruby
Online Store
23.3
Lesson

Default parameter in method

In the last lesson we saw that by default all parameters are required parameters in a method. Ruby allows us to make some parameters as the default value. In the below case we are setting the fahrenheit value to 80. What it means is that if no value is passed then 80 will be the default value.

def initialize(fahrenheit = 80)
  @fahrenheit = fahrenheit
end

Let’s see the default value in action.