Class: Rubie::Interpreter

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

Class Method Summary collapse

Class Method Details

.execObject



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
# File 'lib/rubie/interpreter.rb', line 3

def self.exec
  world = Object.new.send(:binding)

  puts 'おはよう、今日も私と一緒に遊んでくれるんだねっ!嬉しい!'
  while true
    print 'rubie > '
    command = gets
    if command.nil?
      puts "\nまたねー"
      return '遊んでくれてありがとう'
    end
    parser = Rubie::Ripper.new(command)

    begin
      parser.parse
      ret = eval(command, world)
      puts parser.detail
      puts "=> #{ret}"
    rescue Rubie::ParseErrorException => e
      puts "文法エラーみたい・・・ 「#{e.message}」だって"
    rescue ArgumentError => e
      puts '引数違うよー'
    rescue NoMethodError => e
      puts "#{e.receiver}に「#{e.name}」って名前のメソッドが定義されてないってー!"
    rescue NameError => e
      puts "#{e.receiver}に「#{e.name}」って名前の変数かメソッドが定義されてないってー!"
    end
  end
end