Skip to content

Instantly share code, notes, and snippets.

@happyrobots
Created July 9, 2011 05:44
Show Gist options
  • Save happyrobots/1073370 to your computer and use it in GitHub Desktop.
Save happyrobots/1073370 to your computer and use it in GitHub Desktop.
class OptionFilter
def initialize(default_opts)
@default_opts = default_opts
end
def generate(param_name, label_value_pairs)
@copy = @default_opts.clone
@current_param = param_name
label_value_pairs.each { |pair| yield pair[0], opts_for(pair[1]) }
end
private
def opts_for(value)
@copy.merge! @current_param => value
end
end
require 'option_filter'
filter = OptionFilter.new(:hello => 'world', :hoho => 'cur')
filter.generate :hello, [
['Recommended', 'world'],
['Everything', 'all'],
['Latest', 'recent']
] do |name, value|
#link_to name, blah_path(value)
puts "#{name}, #{value}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment