forked from theguitarmaster/rubysage
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplugin.rb
More file actions
32 lines (28 loc) · 634 Bytes
/
Copy pathplugin.rb
File metadata and controls
32 lines (28 loc) · 634 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
module PluginSugar
def def_field(*names)
class_eval do
names.each do |name|
define_method(name) do |*args|
case args.size
when 0: instance_variable_get("@#{name}")
else instance_variable_set("@#{name}", *args)
end
end
end
end
end
end
class Plugin
@registered_plugins = {}
class << self
attr_reader :registered_plugins
private :new
end
def self.define(pattern, &block)
p = new
p.instance_eval(&block)
Plugin.registered_plugins[pattern] = p
end
extend PluginSugar
def_field :name, :details, :version, :usage
end