-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsirb.rb
60 lines (55 loc) · 1006 Bytes
/
sirb.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require 'rubygems'
require 'readline'
require 'tempfile'
require File.dirname(__FILE__) + '/lib/vi'
require File.dirname(__FILE__) + '/lib/sirb/client'
# sirb(main):8D42> vi
# class A
# def poo
# end
# end
# :wq
# sirb(main):8D42> class A
# def poo
# end
# end
# =>nil
# sirb(main:8D42> vi t.rb
# class A
# def poo
# end
# end
# :wq
# ...
# sirb(main:8D42> vi t.rb
# :%s/A/B/g
# :wq
# sirb(main:8D42> B.new
# => <SIRB::B>
#
class SIRBCli
def interpreter
SIRBClient.set_history
prompt = SIRBClient.prompt
loop do
cmd = nil
line = Readline::readline(prompt)
if line =~ /^vi$/
cmd = vi
elsif line =~ /^vi (.*)$/
cmd = vi $1
elsif line =~ /^lload '(.*)'/
cmd = File.read($1)
else
cmd = line
end
exit(0) if line.nil?
unless cmd.nil?
Readline::HISTORY.push(line)
puts SIRBClient.execute(:cmd => cmd, :line => line)
end
end
end
end
sirb = SIRBCli.new
sirb.interpreter