Ruby 2.4.0 リファレンスマニュアル > ライブラリ一覧 > ripperライブラリ > Ripperクラス

class Ripper

クラス・モジュールの継承リスト: Ripper < Object < Kernel < BasicObject

要約

Ruby プログラムのパーサです。

Ruby プログラムをテキストとして扱いたい場合、例えばソース色付けを行いたい場合は、 Ripper::Filter クラスを使うとよいでしょう。

特異メソッド

定義 説明
new(src, filename = "(ripper)", lineno = 1) -> Ripper

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

parse(src, filename = '(ripper)', lineno = 1) -> nil

指定された文字列を解析します。常に nil を返します。

インスタンスメソッド

定義 説明
column -> Integer | nil

現在のトークンの桁番号を 0 から始まる数値で返します。

encoding -> Encoding

自身の持つ Ruby プログラムの文字エンコーディングを返します。

end_seen? -> bool

これまでに解析した Ruby プログラムの中に __END__ が含まれていたかどうかを返します。

filename -> String

自身の持つ Ruby プログラムのファイル名を文字列で返します。

lineno -> Integer | nil

現在のトークンの行番号を 1 から始まる数値で返します。

parse -> nil

自身の持つ Ruby プログラムを解析します。常に nil を返します。

yydebug -> bool

yydebugの構文解析器の追跡機能が有効か無効かを返します。

yydebug=(flag)

yydebugの構文解析器の追跡機能が有効か無効かを指定します。

privateメソッド

定義 説明
compile_error(msg) -> nil

解析した Ruby プログラムの中にコンパイルエラーがあった場合に実行されます。

warn(fmt, *args) -> nil

解析した Ruby プログラムの中に警告($-w が true の時だけ出力される警告)を出力するようなものがあった場合に実行されます。

warning(fmt, *args) -> nil

解析した Ruby プログラムの中に重要な警告($-w が false の時だけ出力される警告)を出力するようなものがあった場合に実行されます。

定数

定義 説明
EVENTS -> [Symbol]

ripper の扱う全てのイベント ID (シンボル) のリストを返します。

PARSER_EVENTS -> [Symbol]

パーサイベントのイベント ID (シンボル) のリストを返します。

PARSER_EVENT_TABLE -> {Symbol => Integer}

パーサイベントのイベント ID (シンボル) と対応するハンドラの引数の個数のリストをハッシュで返します。

SCANNER_EVENTS -> [Symbol]

スキャナイベントのイベント ID (シンボル) のリストを返します。

SCANNER_EVENT_TABLE -> {Symbol => Integer}

スキャナイベントのイベント ID (シンボル) と対応するハンドラの引数の個数のリストをハッシュで返します。

Version -> String

ripper のバージョンを文字列で返します。

継承したメソッド

! != __id__ __send__ instance_eval instance_exec method_missing singleton_method_added singleton_method_removed singleton_method_undefined !~ <=> == === =~ _dump class clone define_singleton_method display enum_for eql? equal? extend freeze frozen? hash initialize initialize_copy inspect instance_of? instance_variable_defined? instance_variable_get instance_variable_set instance_variables is_a? itself marshal_dump marshal_load method methods nil? object_id pretty_inspect pretty_print pretty_print_cycle pretty_print_inspect pretty_print_instance_variables private_methods protected_methods psych_to_yaml public_method public_methods public_send remove_instance_variable respond_to? respond_to_missing? send singleton_class singleton_method singleton_methods taint tainted? tap to_a to_ary to_hash to_int to_io to_proc to_regexp to_s to_str trust untaint untrust untrusted? .yaml_tag ::ARGF ::ARGV ::DATA ::ENV ::FALSE ::NIL ::RUBY_COPYRIGHT ::RUBY_DESCRIPTION ::RUBY_ENGINE ::RUBY_ENGINE_VERSION ::RUBY_PATCHLEVEL ::RUBY_PLATFORM ::RUBY_RELEASE_DATE ::RUBY_REVISION ::RUBY_VERSION ::SCRIPT_LINES__ ::STDERR ::STDIN ::STDOUT ::TOPLEVEL_BINDING ::TRUE

追加されるメソッド

定義 説明 ライブラリ
lex(src, filename = '-', lineno = 1) -> [[Integer, Integer], Symbol, String]

Ruby プログラム str をトークンに分割し、そのリストを返します。ただし Ripper.tokenize と違い、トークンの種類と位置情報も付属します。

ripper/lexer
sexp(src, filename = '-', lineno = 1) -> object

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

ripper/sexp
sexp_raw(src, filename = '-', lineno = 1) -> object

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

ripper/sexp
slice(src, pattern, n = 0) -> String | nil

Ruby プログラム src のうち、パターン pattern の n 番目の括弧にマッチする文字列を取り出します。

ripper/lexer
token_match(src, pattern) -> Ripper::TokenPattern::MatchData | nil

Ruby プログラム src に対してパターン pattern をマッチし、マッチデータを返します。

ripper/lexer
tokenize(src, filename = '-', lineno = 1) -> [String]

Ruby プログラム str をトークンに分割し、そのリストを返します。

ripper/lexer