Lets say I have user input that can be either this:
input = { user_id: 5, ... }
or this:
input = { app_id: 5, ... }
And I want to return either :user_id or :app_id depending on which is provided. I can do this:
(input.keys & [:user_id, :app_id]).first
Is there a more elegant, more rubyish, idiomatic way of doing this?
Is this better or worse than above?:
input.slice(:user_id, :app_id).keys.first
(Answers don't need to be strictly from Ruby 2.2 stdlib, Rails methods welcome as well)