What is the elegant "Ruby Way" of handling nil values?
ruby
Solution
One way is use `Hash#fetch`.
params[:input].to_h.fetch('name', "Name not yet given")
Problem
So I want to conditionally assign variables based on whether or not the input has been given. For example ``` @name = params[:input]['name'] || "Name not yet given" ``` However, if the params have not been passed yet, this gives an error ``` method [] does not exist for nil class ``` I have two ideas to get around this. One is adding a [] method to nil class. Something like: ``` class NilClass def [] self end end ``` And the other idea that I have is to use if statements ``` if params[:input].nil? @name = params[:input]['name'] else @name = "Name not yet given" end ``` However, neither of these solutions feel quite right. What is the "ruby way"?