Skip to content

Instantly share code, notes, and snippets.

@gabrielg
Created January 19, 2012 17:59
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 gabrielg/1641463 to your computer and use it in GitHub Desktop.
Save gabrielg/1641463 to your computer and use it in GitHub Desktop.
class Module
def protocol(proto_name)
@current_protocol = proto_name.to_sym
end
def protocols
@protocols ||= Hash.new{|h,k| h[k] = []}
end
def method_added(name)
return nil if name == :method_added
protocols[@current_protocol || :instance_methods] << name
end
end
class Testing
def name
"Testing object"
end
protocol :accessors
attr_reader :size
attr_accessor :role
protocol :drawing
def moveto
end
end
puts Testing.protocols.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment