Created
December 14, 2015 11:46
-
-
Save vladan-zoricic/41fbb3bc8530153b221a to your computer and use it in GitHub Desktop.
Ruby challenge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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