Created
June 9, 2015 07:06
-
-
Save Shinpeim/5118f23e23f390cae522 to your computer and use it in GitHub Desktop.
This file contains 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
module UserValidator | |
module AdministratorContext | |
def validate! | |
raise "name required" if @name.nil? | |
end | |
end | |
module UserContext | |
def validate! | |
end | |
end | |
end | |
class User | |
def initialize(name) | |
@name = name | |
end | |
def save! | |
validate! | |
end | |
def validate! | |
raise "abstract!" | |
end | |
end | |
u = User.new(nil) | |
u.extend UserValidator::AdministratorContext | |
begin | |
u.save! | |
rescue => e | |
p e | |
end | |
u = User.new(nil) | |
u.extend UserValidator::UserContext | |
u.save! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment