Passing `nil` to method using default named parameters
<p>On a Rails project, I am gathering a hash with 10-15 key-value pairs, and passing it to a class (service object) for instantiation. The object properties should be set from the values in the hash except when there is no value (or <code>nil</code>). In this case, the property would desirably get set to a default value.</p>

<p>Instead of checking whether every value in the hash is not <code>nil</code> before creating an object, I would like to find a more efficient way of doing this.</p>

<p>I'm trying to use named parameters with default values. I don't know if this makes sense, but I would like to use the default value when the parameter is called with <code>nil</code>. I created a test for this functionality:</p>

<pre><code>class Taco
  def initialize(meat: "steak", cheese: true, salsa: "spicy")
    @meat = meat
    @cheese = cheese
    @salsa = salsa
  end
  def assemble
    "taco with: #@meat + #@cheese + #@salsa"
  end
end

options1 = {:meat =&gt; "chicken", :cheese =&gt; false, :salsa =&gt; "mild"}
chickenTaco = Taco.new(options1)
puts chickenTaco.assemble
# =&gt; taco with: chicken + false + mild

options2 = {}
defaultTaco = Taco.new(options2)
puts defaultTaco.assemble
# =&gt; taco with: steak + true + spicy

options3 = {:meat =&gt; "pork", :cheese =&gt; nil, :salsa =&gt; nil}
invalidTaco = Taco.new(options3)
puts invalidTaco.assemble
# expected =&gt; taco with: pork + true + spicy
# actual =&gt; taco with: pork +  +
</code></pre>