種類
- インスタンスメソッド (116)
- モジュール関数 (60)
- モジュール (24)
- 特異メソッド (24)
- クラス (12)
クラス
- ERB (140)
モジュール
-
ERB
:: DefMethod (12) -
ERB
:: Util (48)
キーワード
- DefMethod (12)
- ERB (12)
- Util (12)
-
def
_ class (12) -
def
_ erb _ method (12) -
def
_ method (12) -
def
_ module (12) - filename (12)
- filename= (12)
- h (12)
-
html
_ escape (12) - new (12)
- result (12)
-
result
_ with _ hash (8) - run (12)
-
set
_ eoutvar (12) - src (12)
- u (12)
-
url
_ encode (12) - version (12)
検索結果
先頭5件
-
ERB (2.0)
-
eRuby スクリプトを処理するクラス。
...。
従来 ERbLight と呼ばれていたもので、
標準出力への印字が文字列の挿入とならない点が eruby と異なります。
* https://magazine.rubyist.net/articles/0017/0017-BundledLibraries.html
=== 使い方
ERB クラスを使うためには require 'erb' する必......要があります。
例:
require 'erb'
ERB.new($<.read).run
=== trim_mode
trim_mode は整形の挙動を変更するオプションです。次の振舞いを指定できます。
* 改行の扱い
* %ではじまる行の扱い (ERB 2.0 から追加されました)
trim_mode に......指定できる値は次の通りです。
* ERb-1.4.x 互換の指定方法
* nil, 0: そのまま変換
* 1: 行末が%>のとき改行を出力しない
* 2: 行頭が<%で行末が%>のとき改行を出力しない
* 2.0 からの指定方法
* nil, "": そのまま変換... -
ERB
# def _ class(superklass=Object , methodname=& # 39;erb& # 39;) -> Class (2.0) -
変換した Ruby スクリプトをメソッドとして定義した無名のクラスを返します。
...mlist[例][ruby]{
require 'erb'
class MyClass_
def initialize(arg1, arg2)
@arg1 = arg1; @arg2 = arg2
end
end
filename = 'example.rhtml' # @arg1 と @arg2 が使われている example.rhtml
erb = ERB.new(File.read(filename))
erb.filename = filename
MyClass = erb.def_class(MyClass_, 'rend... -
ERB
# def _ method(mod , methodname , fname=& # 39;(ERB)& # 39;) -> nil (2.0) -
変換した Ruby スクリプトをメソッドとして定義します。
...に活躍します。
@param mod メソッドを定義するモジュール(またはクラス)
@param methodname メソッド名
@param fname スクリプトを定義する際のファイル名
例:
require 'erb'
erb = ERB.new(script)
erb.def_method(MyClass, 'foo(bar)', 'foo.erb')... -
ERB
# def _ module(methodname=& # 39;erb& # 39;) -> Module (2.0) -
変換した Ruby スクリプトをメソッドとして定義した無名のモジュールを返します。
...ルを返します。
@param methodname メソッド名
//emlist[例][ruby]{
require 'erb'
filename = 'example.rhtml'
erb = ERB.new("test1<%= arg1 %>\ntest2<%= arg2 %>\n")
erb.filename = filename
MyModule = erb.def_module('render(arg1, arg2)')
class MyClass
include MyModule
end
print MyClass.new... -
ERB
# filename -> String (2.0) -
エラーメッセージを表示する際のファイル名を取得します。
...エラーメッセージを表示する際のファイル名を取得します。
//emlist[例][ruby]{
require 'erb'
filename = 'example.rhtml'
erb = ERB.new(File.read(filename))
erb.filename # => nil
erb.filename = filename
erb.filename # =>"example.rhtml"
//}... -
ERB
# filename= -> String (2.0) -
エラーメッセージを表示する際のファイル名を設定します。
...filename を設定していない場合は、エラー発生箇所は「 (ERB) 」という出力となります。
//emlist[例][ruby]{
require 'erb'
filename = 'example.rhtml'
erb = ERB.new(File.read(filename))
erb.filename # => nil
erb.filename = filename
erb.filename # =>"example.rhtml"
//}... -
ERB
# result(b=TOPLEVEL _ BINDING) -> String (2.0) -
ERB を b の binding で実行し、結果の文字列を返します。
...
ERB を b の binding で実行し、結果の文字列を返します。
@param b eRubyスクリプトが実行されるときのbinding
//emlist[例][ruby]{
require 'erb'
erb = ERB.new("test <%= test1 %>\ntest <%= test2 %>\n")
test1 = "foo"
test2 = "bar"
puts erb.result
# test foo
# test bar
//......}
@see ERB#result_with_hash... -
ERB
# result _ with _ hash(hash) -> String (2.0) -
ERB をハッシュオブジェクトで指定されたローカル変数を持つ 新しいトップレベルバインディングで実行し、結果の文字列を返します。
...
ERB をハッシュオブジェクトで指定されたローカル変数を持つ
新しいトップレベルバインディングで実行し、結果の文字列を返します。
@param hash ローカル変数名をキーにしたハッシュ
@see ERB#result... -
ERB
# run(b=TOPLEVEL _ BINDING) -> nil (2.0) -
ERB を b の binding で実行し、結果を標準出力へ印字します。
...
ERB を b の binding で実行し、結果を標準出力へ印字します。
@param b eRubyスクリプトが実行されるときのbinding
//emlist[例][ruby]{
require 'erb'
erb = ERB.new("test <%= test1 %>\ntest <%= test2 %>\n")
test1 = "foo"
test2 = "bar"
erb.run
# test foo
# test bar
//}...