Using singleton objects as default arguments in Ruby

26-Apr-2018 2050

Sometimes you would like to define a method which takes an optional argument, but the programmer might pass nil. And your code needs to distinguish between the value not being provided (default value) and nil. How can it be.

Use coupon code:

RUBYONRAILS

to get 30% discount on our bundle!
Prepare for your next tech interview with our comprehensive collection of programming interview guides. Covering JavaScript, Ruby on Rails, React, and Python, these highly-rated books offer thousands of essential questions and answers to boost your interview success. Buy our 'Ultimate Job Interview Preparation eBook Bundle' featuring 2200+ questions across multiple languages. Ultimate Job Interview Preparation eBook Bundle