Class: Eggsh::Translator

Inherits:
Object show all
Defined in:
lib/translator.rb

Instance Method Summary collapse

Instance Method Details

#translate(line) ⇒ Object

translate a certain line with ruby expression



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/translator.rb', line 6

def translate line
  eval_str, result, count = "", "", 0
  for i in line.split ''
    count += 1 if i == '{'
    if count == 0
      result += eval_part(eval_str).to_cmd + i
      eval_str = ''
    else
      eval_str += i
    end
    count -= 1 if i == '}'
  end
  result += eval_part(eval_str).to_cmd
  raise 'eggsh: Unbalanced parenthesis' if count != 0
  result
end