Skip to content

Instantly share code, notes, and snippets.

@vladan-zoricic
Created December 14, 2015 11:46
Show Gist options
  • Save vladan-zoricic/41fbb3bc8530153b221a to your computer and use it in GitHub Desktop.
Save vladan-zoricic/41fbb3bc8530153b221a to your computer and use it in GitHub Desktop.
Ruby challenge
class DevvController < ApplicationController
def options
options = {}
available_option_keys = [:awesome, :ruby, :developer]
all_keys = params.keys.map(&:to_sym)
#this is wrong, we can not concatenate arrays with '&' operator, we should use '&&' or '+' operator
set_option_keys = all_keys & available_option_keys
set_option_keys.each do |key|
options[key] = params[key]
end
#options hash contains elements with nil value, so we should remove those elements
options.delete_if{|k, v| v.nil?}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment