Learn Ruby
Online Store
23.3
Lesson

Default argument

In the last lesson we saw that if the argument is not passed to method then method fails. However there is a way to declare default value for an argument. Let’s see it in action

In the above case we are not passing any argument to new. However we have set a default value for condition. If no value is passed then hot will be the default value.

Let’s see one more example.

In the above case car1 is created without passing any parameter. So the color of car1 will be black.

For car2 the color red was passed so the red color will be applied to car2.