Class: SciRuby::Plotter::Interpreter
- Inherits:
-
Object
- Object
- SciRuby::Plotter::Interpreter
- Defined in:
- lib/sciruby/plotter.rb
Overview
A simple REPL without the P. Based roughly on IRB. Look on Wikipedia if you’re not sure what a REPL is.
Instance Attribute Summary collapse
-
#bind ⇒ Object
readonly
Returns the value of attribute bind.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
- #eval_script ⇒ Object
-
#initialize(filename, script = nil) ⇒ Interpreter
constructor
A new instance of Interpreter.
Constructor Details
#initialize(filename, script = nil) ⇒ Interpreter
Returns a new instance of Interpreter.
70 71 72 73 74 75 76 77 78 |
# File 'lib/sciruby/plotter.rb', line 70 def initialize filename, script = nil @filename = filename @bind = binding @script = script.nil? ? File.new(filename, "r") : StringIO.new(script) @script.define_singleton_method(:encoding, lambda { external_encoding }) unless @script.respond_to?(:encoding) @scanner = ::RubyLex.new @scanner.set_input @script end |
Instance Attribute Details
#bind ⇒ Object (readonly)
Returns the value of attribute bind.
80 81 82 |
# File 'lib/sciruby/plotter.rb', line 80 def bind @bind end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
80 81 82 |
# File 'lib/sciruby/plotter.rb', line 80 def filename @filename end |
Instance Method Details
#eval_script ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/sciruby/plotter.rb', line 82 def eval_script vis = nil @scanner.each_top_level_statement do |line, line_number| line.untaint vis = eval(line, bind, filename, line_number) end vis = eval("vis", bind, __FILE__, __LINE__) unless vis.is_a?(::Rubyvis::Panel) vis.render() vis end |