Skip to content

Instantly share code, notes, and snippets.

@orbanbotond
Created September 10, 2012 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orbanbotond/3690538 to your computer and use it in GitHub Desktop.
Save orbanbotond/3690538 to your computer and use it in GitHub Desktop.
Question for an interview
module SolrFilter
module ClassMethods
def do_guess_what(*args)
args.each do |arg|
define_method "#{arg.to_s}_solr_filtered" do
send(arg).gsub /\'/, ''
end
end
end
end
def self.included(base)
base.extend(ClassMethods)
end
end
class A
include SolrFilter
do_guess_what :name, :city
def name
'Char\'s'
end
def city
'City\'har\'s'
end
end
a = A.new
puts "Name: #{a.name} City: #{a.city}"
puts "Name: #{a.name_solr_filtered} City: #{a.city_solr_filtered}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment