title: Ruby method with argument hash with default values: how to DRY?
body: <p>I have an <code>initialize</code> method that accepts a hash to set some instance variables. This is basically what I'm trying to do:</p>
  
  <pre><code>class Ad
    DEFAULT_PAGE = 'index'.freeze
  
    DEFAULT_CHANNEL = 'general'.freeze
  
    DEFAULT_AREA = 'general'.freeze
  
    attr_accessor :page, :area, :channel
  
    def initialize args={}
      @page = args[:page] || DEFAULT_PAGE
      @area = args[:area] || DEFAULT_AREA
      @channel = args[:channel] || DEFAULT_CHANNEL
    end
  
    # ...
  end
  </code></pre>
  
  <p>I saw a tip to allow dynamic setting of instance variables, but I'm not sure how to also include the default values...</p>
  
  <pre><code>  def initialize args={}
      args.each do |attr,val|
        instance_variable_set("@#{attr}", val) unless val.nil?
      end
    end
  </code></pre>
  
  <p>Can I refer to a constant dynamically? Or any better ways of doing this sort of thing are welcome!</p>
  
  <p>... I also realize that <code>attr_accessor</code> variables can be set individually. But I just want to do it like this. :)</p>