るりまサーチ

最速Rubyリファレンスマニュアル検索!
55件ヒット [1-55件を表示] (0.027秒)
トップページ > クエリ:new[x] > ライブラリ:ripper[x]

別のキーワード

  1. openssl new
  2. _builtin new
  3. rexml/document new
  4. resolv new
  5. socket new

種類

クラス

キーワード

検索結果

Ripper.new(src, filename = "(ripper)", lineno = 1) -> Ripper (18103.0)

Ripper オブジェクトを作成します。

...
Ripper
オブジェクトを作成します。

@param src Ruby プログラムを文字列か IO オブジェクトで指定します。

@param filename src のファイル名を文字列で指定します。省略すると "(ripper)" になります。

@param lineno src の開始行番号を指...
...定します。省略すると 1 になります。

src の解析を行うには更に Ripper#parse などの呼び出しが必要です。

@see Ripper.parse, Ripper#parse...

Ripper::Filter.new(src, filename = '-', lineno = 1) -> Ripper::Filter (18102.0)

Ripper::Filter オブジェクトを作成します。

...
Ripper
::Filter オブジェクトを作成します。

@param src Ruby プログラムを文字列か IO オブジェクトで指定します。

@param filename src のファイル名を文字列で指定します。省略すると "-" になります。

@param lineno src の開始行番号を...

Ripper.sexp(src, filename = '-', lineno = 1) -> object (13.0)

Ruby プログラム str を解析して S 式のツリーにして返します。

...結果は、括弧の代わりに配列の要素として S 式のツリーを表現しています。

//emlist[例][ruby]{
require 'ripper'
require 'pp'

pp Ripper.sexp("def m(a) nil end")
# => [:program,
# [[:def,
# [:@ident, "m", [1, 4]],
# [:paren, [:params, [[:@ident, "a", [1,...
...ークン, 位置情報(行、桁の配列)]

例:

[:@ident, "m", [1, 4]]

また、Ripper.sexp は Ripper.sexp_raw とは異なり、読みやすさのため
に stmts_add や stmts_new のような _add、_new で終わるパーサイベントを
省略します。_add で終わるパーサイ...
...ベントはハンドラの引数が 0 個のものが
省略されます。詳しくは Ripper::PARSER_EVENTS を確認してください。

@see Ripper.sexp_raw...

Ripper.sexp_raw(src, filename = '-', lineno = 1) -> object (13.0)

Ruby プログラム str を解析して S 式のツリーにして返します。

...quire 'ripper'
require 'pp'

pp Ripper.sexp_raw("def m(a) nil end")
# => [:program,
# [:stmts_add,
# [:stmts_new],
# [:def,
# [:@ident, "m", [1, 4]],
# [:paren, [:params, [[:@ident, "a", [1, 6]]], nil, nil, nil]],
# [:bodystmt,
# [:stmts_add, [:stmts_new], [:va...
...r_ref, [:@kw, "nil", [1, 9]]]],
# nil,
# nil,
# nil]]]]
//}

Ripper
.sexp_raw は Ripper.sexp とは異なり解析結果を加工しません。

@see Ripper.sexp...

Ripper::Filter (7.0)

イベントドリブンスタイルで Ruby プログラムを加工するためのクラスです。

...必要なイベントに対応するメソッドを定義して使用し
ます。

=== 使用例

//emlist[][ruby]{
require 'ripper'
require 'cgi'

class Ruby2HTML < Ripper::Filter
def on_default(event, tok, f)
f << CGI.escapeHTML(tok)
end

def on_comment(tok, f)
f << %Q[<span class="...
...capeHTML(tok)}]
end

def on_tstring_end(tok, f)
f << %Q[#{CGI.escapeHTML(tok)}</span>]
end
end

Ruby2HTML.new(ARGF).parse('')
//}

Ruby プログラムを解析して、Ripper::SCANNER_EVENTS にあるスキャナ
イベントを実行します。イベントはプログラムに書いた...

絞り込み条件を変える