문제

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
도움이 되었습니까?

해결책

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).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top