Created
September 12, 2012 07:31
-
-
Save svs/3704962 to your computer and use it in GitHub Desktop.
descriptive method calls
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
class Person | |
attr_accessor :name, :role | |
def initialize(name, role) | |
@name, @role = name, role | |
end | |
# options is a Hash with the following keys | |
# :to -> the role to set to | |
# :if -> a Symbol. This method will be called and must return true in order to set the role | |
def set_role(options) | |
raise ArgumentError.new('Must specify :to and :if') unless options.slice(:to,:if).count < 2 | |
cond = self.send(options[:if]) if options[:if].class == Symbol | |
@role = options[:to] if cond | |
end | |
end | |
p = Person.new("svs",:inside_subscriber) | |
p.set_role(:to => :outside_subscriber, :if => :all_access_revoked?) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment