Ruby 2.1.0 リファレンスマニュアル > ライブラリ一覧 > erbライブラリ > ERBクラス > result

instance method ERB#result

result(b=TOPLEVEL_BINDING) -> String[permalink][rdoc]

ERB を b の binding で実行し、結果の文字列を返します。

[PARAM] b:
eRubyスクリプトが実行されるときのbinding


require 'erb'
erb = ERB.new("test <%= test1 %>\ntest <%= test2 %>\n")
test1 = "foo"
test2 = "bar"
puts erb.result
# test foo
# test bar