From: m_seki@... Date: 2000-03-06T08:41:22+09:00 Subject: [ruby-talk:01731] Re: using eRuby from inside Ruby >>>>> "M" == Michael Neumann writes: M> Is it possible to use eRuby from Ruby without executing it, only through a method-call. M> Could it be loaded as module? I wrote 'Tiny eRuby - ERb'. ERb is an implementation of eRuby (embedded ruby). You can include ERb in your script. o ERb#new(str) convert eRuby -> Ruby. o ERb#run([binding]) execute script, and print result. o ERb#result([binding]) execute script, and return result. o ERb#src converted Ruby script. You can use it following way. -- ERb sample script -- require 'erb/erb' # http://www2a.biglobe.ne.jp/~seki/ruby/erb-1.2.tar.gz class App def initialize # eRuby script script = < <% hash.each { |k, v| %>
<%= k %>
<%= v %> <% } %> EOS # eRuby -> ERb @erb = ERb.new(script) end def display(hash) # eval @erb.result(binding) end def debug puts @erb.src end end app = App.new puts "

ENV

" puts app.display(ENV) puts "

Seki

" puts app.display({'given'=>'Masatoshi', 'family'=>'SEKI', 'age'=>29})