Ruby Issue Tracking System: Issueshttps://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112016-02-20T12:00:20ZRuby Issue Tracking System
Redmine Ruby master - Feature #12093 (Rejected): Eval InstructionSequence with bindinghttps://bugs.ruby-lang.org/issues/120932016-02-20T12:00:20Zpavel.evstigneev (Pavel Evstigneev)
<p>Implementing this feature can boost template engine performance</p>
<p>Currently Kernel#eval can accept binding argument, so code running with eval will have access to local variables and current instance. This feature used by template languages</p>
<p>ERB: <a href="https://github.com/ruby/ruby/blob/trunk/lib/erb.rb#L887" class="external">https://github.com/ruby/ruby/blob/trunk/lib/erb.rb#L887</a><br>
Erubis: Can't find code on github, but it uses instance_eval or Kernel#eval<br>
Haml: <a href="https://github.com/haml/haml/blob/master/lib/haml/engine.rb#L115" class="external">https://github.com/haml/haml/blob/master/lib/haml/engine.rb#L115</a></p>
<p>My proposal is to make RubyVM::InstructionSequence#eval to recieve binding argument. So it can be used for caching templates. As I see from ERB and Haml, cached template is stored as ruby code string, every time when we render template that string (ruby code) is evaluated, internally ruby will parse it into RubyVM::InstructionSequence and then evaluate.</p>
<p>Before I try to implement it myself in ruby, but could not. Lack of experience with C <a href="https://github.com/Paxa/ruby/commit/f5b602b6d9eada9675a4c002c9a5a79129df73a6" class="external">https://github.com/Paxa/ruby/commit/f5b602b6d9eada9675a4c002c9a5a79129df73a6</a> (not working)</p>