Created
July 24, 2012 16:34
-
-
Save omgitsads/3171063 to your computer and use it in GitHub Desktop.
Scamp V2 plugin prototype
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
class Scamp | |
def say str | |
puts "BOT: #{str.inspect}" | |
end | |
def behaviour &block | |
instance_eval(&block) | |
end | |
def plugin klass | |
klass.new.to_proc[self] | |
end | |
end | |
module Scamp::Plugin | |
def to_proc | |
method(:behaviour).to_proc | |
end | |
end | |
class PluginOne | |
include Scamp::Plugin | |
def string | |
"plugin" | |
end | |
def behaviour bot | |
bot.say string | |
end | |
end | |
class PluginTwo | |
include Scamp::Plugin | |
def behaviour bot | |
bot.say "Hello" | |
end | |
end | |
s = Scamp.new | |
s.plugin PluginOne | |
# >> BOT: "plugin" | |
s.plugin PluginTwo | |
# >> BOT: "Hello" | |
s.behaviour { say "Hello, World" } | |
# >> BOT: "Hello, World" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment