Refactoring if statement based on a hash key I have to call Article.to_draft/to_archive/publish method depending on the presence of the corresponding key in the params hash.

I do, however, have no idea to implement it properly.

def update_state
  method = if params[:draft].present?
             :to_draft
           elsif params[:archived].present?
             :to_archive
           else
             :publish
           end
  @article.send method
end


The code works, but the number of possible states of an article will probably grow in the future. 

I would like to have a hash like this:

{ draft: :to_draft, archived: :to_archive, default: :publish }


and let #update_state decide what should be called, based on the params hash.
I suggest using find

ARTICLE_ACTIONS = { :draft =&gt; :to_draft,
                    :archived =&gt; :to_archive,
                    :default =&gt; :publish 
                  }

def update_state
  state = [:draft, :archived, :default]
             .find {|state| params[state].present?}
  @article.send ARTICLE_ACTIONS[state]
end