Skip to content

Instantly share code, notes, and snippets.

@omgitsads
Created July 24, 2012 16:34
Show Gist options
  • Save omgitsads/3171063 to your computer and use it in GitHub Desktop.
Save omgitsads/3171063 to your computer and use it in GitHub Desktop.
Scamp V2 plugin prototype
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