Learn Ruby
Online Store

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

Let’s see the default value in action.