Class: DataStory::EvalContext
- Inherits:
-
Object
- Object
- DataStory::EvalContext
- Defined in:
- lib/datastory/eval_context.rb
Class Method Summary collapse
- .eval_binding ⇒ Object
-
.evaluate(code) ⇒ Object
Public: Evaluates the passed code in this context.
-
.evaluate_erb(code) ⇒ Object
Public: Evaluates some ERb in this context.
Class Method Details
.eval_binding ⇒ Object
29 30 31 |
# File 'lib/datastory/eval_context.rb', line 29 def self.eval_binding @binding ||= eval("binding") end |
.evaluate(code) ⇒ Object
Public: Evaluates the passed code in this context.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/datastory/eval_context.rb', line 7 def self.evaluate(code) prev_stdout = $stdout #prev_stderr = $stderr out = StringIO.new $stdout = out #$stderr = out eval(code, eval_binding) $stdout = prev_stdout #$stderr = prev_stderr out.string end |
.evaluate_erb(code) ⇒ Object
Public: Evaluates some ERb in this context.
24 25 26 27 |
# File 'lib/datastory/eval_context.rb', line 24 def self.evaluate_erb(code) erb = Erubis::EscapedEruby.new(code) erb.result(eval_binding) end |