Module: Ripl

Extended by:
Ripl
Included in:
Ripl
Defined in:
lib/ripl.rb,
lib/ripl/shell.rb,
lib/ripl/version.rb,
lib/ripl/completion.rb

Defined Under Namespace

Modules: Completion, Hooks Classes: ReadlineShell, Shell

Constant Summary collapse

VERSION =
'0.1.2'

Instance Method Summary collapse

Instance Method Details

#parse_options(argv) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ripl.rb', line 12

def parse_options(argv)
  while argv[0] =~ /^-/
    case argv.shift
    when /-I=?(.*)/
      $LOAD_PATH.unshift(*$1.split(":"))
    when /-r=?(.*)/
      require $1
    when '-v', '--version'
      puts Ripl::VERSION; exit
    end
  end
end

#runObject



7
8
9
10
# File 'lib/ripl.rb', line 7

def run
  parse_options(ARGV)
  ARGV[0] ? run_command(ARGV) : start
end

#run_command(argv) ⇒ Object



25
26
27
28
29
30
# File 'lib/ripl.rb', line 25

def run_command(argv)
  exec "ripl-#{argv.shift}", *argv
rescue Errno::ENOENT
  raise unless $!.message =~ /No such file or directory.*ripl-(\w+)/
  abort "`#{$1}' is not a ripl command."
end

#shell(options = {}) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/ripl.rb', line 36

def shell(options={})
  @shell ||= begin
    require 'ripl/readline_shell'
    ReadlineShell.new(options)
  rescue LoadError
    Shell.new(options)
  end
end

#start(options = {}) ⇒ Object



32
33
34
# File 'lib/ripl.rb', line 32

def start(options={})
  shell(options).loop
end