Class: IRuby::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/iruby/command.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Command

Returns a new instance of Command.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/iruby/command.rb', line 6

def initialize(args)
  @args = args

  ipython_dir = ENV['IPYTHONDIR'] || '~/.ipython'
  @args.each do |arg|
    ipython_dir = $1 if arg =~ /\A--ipython-dir=(.*)\Z/
  end
  @kernel_dir = File.join(File.expand_path(ipython_dir), 'kernels', 'ruby')
  @kernel_file = File.join(@kernel_dir, 'kernel.json')
  @iruby_path = File.expand_path $0
end

Instance Method Details

#runObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/iruby/command.rb', line 18

def run
  case @args.first
  when 'version', '-v', '--version'
    require 'iruby/version'
    puts "IRuby #{IRuby::VERSION}, Ruby #{RUBY_VERSION}"
  when 'help', '-h', '--help'
    print_help
  when 'register'
    if registered_iruby_path && !@args.include?('--force')
      STDERR.puts "#{@kernel_file} already exists!\nUse --force to force a register."
      exit 1
    end
    register_kernel
  when 'unregister'
    unregister_kernel
  when 'kernel'
    run_kernel
  else
    run_ipython
  end
end