Skip to content

Instantly share code, notes, and snippets.

@vierarb
Created February 21, 2014 15:49
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 vierarb/9136686 to your computer and use it in GitHub Desktop.
Save vierarb/9136686 to your computer and use it in GitHub Desktop.
method_missing
class Speciality < ActiveRecord::Base
validates :code, presence: true
private
def method_missing(method, *args, &block)
if method.to_s =~ /^(.+)[?]$/
run_code_comparation_method($1, *args, &block)
else
super
end
end
def run_code_comparation_method(attrs, *args, &block)
attributes['code'] == attrs
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment