Created
October 16, 2012 22:14
-
-
Save efatsi/3902392 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
validates_presence_of :name, :if => :require_name, :on => :update | |
validates_presence_of :email, :if => :require_email, :on => :update | |
validates_presence_of :phone, :if => :require_phone, :on => :update | |
def method_missing(name) | |
if name.to_s =~ /require_\w+/ | |
project.present? && project.send(name) | |
else | |
super | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
validates_presence_of :name, :if => :require_name, :on => :update | |
validates_presence_of :email, :if => :require_email, :on => :update | |
validates_presence_of :phone, :if => :require_phone, :on => :update | |
def require_name | |
project.require_name | |
end | |
def require_name | |
project.require_email | |
end | |
def require_email | |
project.require_phone | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
delegate
is the right choice here, but if that wasn't an option, this would be my preferred refactoring: