Question

I have developed a simple DSL for tasks on a UniVerse database in jruby. It looks something like this

support = { 
    :host => 'localhost', 
    :account => 'SUPPORT'
}

uni_task support do 
    connect
    exec "LIST FILE A1"
    disconnect
end

and is implemented like this

def uni_task(config, &block)
    session = UniSession.new
    session.instance_eval &block
end

I'm aware that you can drop to irb in a ruby script like this

But is there a way to drop to a command line and have the scope changed to execute instance methods of an object by default?

Eg

irb> uni_commandline support
uni> connect
uni> exec "LIST FILE A1"

     .... output .....

uni> disconnect
Was it helpful?

Solution

In irb you can use the irb command to move inside an object scope:

irb> irb some_object

from then on any commands will execute inside the scope of that object (so you can call its instance methods directly).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top