Question: I find that I've been doing this a fair enough number of times in my Rails controllers that I'm interested in finding a better way of writing it out (if possible). Essentially, I'm validating the input to a few options, and falling back on a default value if the input doesn't match any of the options.

```
valid_options = %w(most_active most_recent most_popular)
@my_param = valid_options.include?(params[:my_param]) ? params[:my_param] : 'most_recent'

```

Answer: 
If you use a hash instead of an array, it would be faster and cleaner. And, since your default is `"most_recent"`, having `"most_recent"` in `valid_options` is redundant. You better remove it.

```
filter_options =
Hash.new("most_recent")
.merge("most_popular" => "most_popular", "most_active" => "most_active")

@my_param = filter_options[params[:my_param]]

```
I too would go the Hash route.

This could be imaginable:

```
Hash[valid_options.zip valid_options].fetch(params[:my_param], "most_recent")

```