-
-
Save nuke99/9d1a968f5474802b9e3d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/ruby | |
require 'readline' | |
class Var | |
@@prompt = 'loka' | |
@@current_module = nil | |
end | |
module Test | |
class TestAgain < Var | |
def initialize | |
@@prompt = "testagainmodule" | |
end | |
def example | |
puts "This is a exmaple output" | |
end | |
def help | |
puts "This is help" | |
end | |
end | |
end | |
class Prompt < Var | |
include Test | |
def prompt | |
@@current_module = self | |
while inline = Readline.readline( @@prompt + " >",true) | |
#puts @@current_module | |
method , cmd = inline.split | |
if @@current_module.respond_to? method | |
parameter_count = @@current_module.method(method.to_sym).arity | |
if parameter_count == 1 | |
@@current_module.send(method, cmd) | |
else | |
@@current_module.send(method) | |
end | |
else | |
puts "Unknown Command " + inline | |
end | |
exit if inline == "exit" | |
end | |
end | |
def mods(val) | |
puts "loading module "+val | |
klass = Test.const_get(val) | |
@@current_module = klass.new | |
end | |
def unload | |
puts "unloading module .." | |
@@current_module = self | |
end | |
end | |
prompt = Prompt.new() | |
prompt.prompt | |
#what i want to do is | |
# loka >example | |
# Unknown Command example | |
# loka > mods TestAgain | |
# loading module TestAgain | |
# testagainmodule > example | |
# This is a exmaple output | |
# testagainmodule > unload | |
# unloading module .. | |
# loka > |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment