Module: EasyRepl::Repl

Included in:
EasyRepl
Defined in:
lib/easy_repl/repl.rb

Instance Method Summary collapse

Instance Method Details

#getsObject



48
49
50
51
52
53
54
55
56
57
# File 'lib/easy_repl/repl.rb', line 48

def gets
  input = prompt.gets
  command = commands.find {|c| c.matches(input)}
  if command
    command.run
    return ""
  else
    return input
  end
end

#startObject



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
# File 'lib/easy_repl/repl.rb', line 18

def start
  IRB::HistorySavingAbility.extend(IRB::HistorySavingAbility) unless IRB::HistorySavingAbility === IRB::HistorySavingAbility
  loop do
    setup if respond_to? :setup
    begin
      exit_value = catch(:exit_repl) do
        loop do
          begin
            before_input if respond_to? :before_input
            if block_given?
              yield EasyRepl.gets
            elsif respond_to? :process_input
              process_input(EasyRepl.gets)
            else
              puts EasyRepl.gets
            end
          ensure
            after_input if respond_to? :after_input
          end
        end
      end
      return if exit_value == :exit
    ensure
      teardown if respond_to? :teardown
    end
  end
ensure
  IRB::HistorySavingAbility.save_history
end