Skip to content

Instantly share code, notes, and snippets.

@svs
Created September 12, 2012 07:31
Show Gist options
  • Save svs/3704962 to your computer and use it in GitHub Desktop.
Save svs/3704962 to your computer and use it in GitHub Desktop.
descriptive method calls
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