Ensure that a Sinatra hash always has a valid value
up vote
0
down vote
favorite
I'm trying to ensure that a Sinatra hash always has a valid value.
Is there a more-concise way to write this?
params[:v] = if [:icons,:list].include? (params[:v] ||= :list).downcase.to_sym then (params[:v] ||= :list).downcase.to_sym else :list end
ruby sinatra
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
up vote
0
down vote
favorite
I'm trying to ensure that a Sinatra hash always has a valid value.
Is there a more-concise way to write this?
params[:v] = if [:icons,:list].include? (params[:v] ||= :list).downcase.to_sym then (params[:v] ||= :list).downcase.to_sym else :list end
ruby sinatra
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
I'm really unsure what your goal is here. Can you clarify?
– thesecretmaster
Jul 20 at 2:59
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to ensure that a Sinatra hash always has a valid value.
Is there a more-concise way to write this?
params[:v] = if [:icons,:list].include? (params[:v] ||= :list).downcase.to_sym then (params[:v] ||= :list).downcase.to_sym else :list end
ruby sinatra
I'm trying to ensure that a Sinatra hash always has a valid value.
Is there a more-concise way to write this?
params[:v] = if [:icons,:list].include? (params[:v] ||= :list).downcase.to_sym then (params[:v] ||= :list).downcase.to_sym else :list end
ruby sinatra
ruby sinatra
asked Jun 26 at 19:41
craig
1085
1085
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
I'm really unsure what your goal is here. Can you clarify?
– thesecretmaster
Jul 20 at 2:59
add a comment |
I'm really unsure what your goal is here. Can you clarify?
– thesecretmaster
Jul 20 at 2:59
I'm really unsure what your goal is here. Can you clarify?
– thesecretmaster
Jul 20 at 2:59
I'm really unsure what your goal is here. Can you clarify?
– thesecretmaster
Jul 20 at 2:59
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
I'd write this in multiple lines, so that you don't have to write out the complex conversion multiple times:
v = (params[:v] || :list).downcase.to_sym
params[:v] = if %i[icons list].include?(v) then v else :list end
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I'd write this in multiple lines, so that you don't have to write out the complex conversion multiple times:
v = (params[:v] || :list).downcase.to_sym
params[:v] = if %i[icons list].include?(v) then v else :list end
add a comment |
up vote
0
down vote
I'd write this in multiple lines, so that you don't have to write out the complex conversion multiple times:
v = (params[:v] || :list).downcase.to_sym
params[:v] = if %i[icons list].include?(v) then v else :list end
add a comment |
up vote
0
down vote
up vote
0
down vote
I'd write this in multiple lines, so that you don't have to write out the complex conversion multiple times:
v = (params[:v] || :list).downcase.to_sym
params[:v] = if %i[icons list].include?(v) then v else :list end
I'd write this in multiple lines, so that you don't have to write out the complex conversion multiple times:
v = (params[:v] || :list).downcase.to_sym
params[:v] = if %i[icons list].include?(v) then v else :list end
answered Jul 22 at 23:37
David Maze
1011
1011
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f197306%2fensure-that-a-sinatra-hash-always-has-a-valid-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I'm really unsure what your goal is here. Can you clarify?
– thesecretmaster
Jul 20 at 2:59