Class: Rust

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stdin = $stdin, stdout = $stdout, stderr = $stderr) ⇒ Rust

Returns a new instance of Rust.



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

def initialize(stdin=$stdin, stdout=$stdout, stderr=$stderr)
  $stdin, $stdout, $stderr = stdin, stdout, stderr

  $keys ||= {}
  @history = []
  @io = InOut.new(stdin, stdout, stderr, $keys)
  @@io = @io # a nice hack for parser compatiblity

  run
end

Class Method Details

.ioObject

Used by the parser



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

def self.io
  @@io
end

Instance Method Details

#promptObject



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/rust/rust.rb', line 60

def prompt
  line = ''
  loop {
    line += ask($prompt)
    #      unless line.slice(-1) =~ /\\/
    @history << line
    $parser.execute line.strip unless line.strip =~ /^$/ # $parser.execute line
    line = ''
    #      end
  }
end

#runObject



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

def run
  ######
  ## Read the user's .rustrc file
  if File.exist? "#{ENV['HOME']}/.rustrc"
    CommandCenter.instance_eval(File.read("#{ENV['HOME']}/.rustrc"))
  else
    File.open("#{ENV['HOME']}/.rustrc", 'w')
  end

  prompt
end