24件ヒット
[1-24件を表示]
(0.026秒)
別のキーワード
検索結果
-
IRB
:: Inspector . def _ inspector(key , arg = nil) { |v| . . . } -> object (18208.0) -
新しい実行結果の出力方式を定義します。
...ロックを指定しない場合には、実行結果の出力のための手続きオ
ブジェクトを指定します。
例.
# .irbrc
IRB::Inspector.def_inspector([:test]){ |v| v.to_s * 2 }
$ irb --inspect test
irb(main):001:0> :abc # => abcabc
@see lib:irb#inspect_mode... -
irb (18.0)
-
irb は Interactive Ruby の略です。 irb を使うと、Ruby の式を標準入力から簡単に入力・実行することができます。
...# サブ irb を起動
irb#1(main):001:0> x # x を表示
NameError: undefined local variable or method `x' for main:Object
from (irb#1):1:in `Kernel#binding'
起動時のインタプリタでローカル変数 x を定義しましたが、
「irb」でサブ irb......ところが、 irb ではエラーになります。
irb(main):001:0> eval "foo"
NameError (undefined local variable or method `foo' for main:Object)
irb(main):002:0> foo = 0
この違いは、Ruby スクリプト と irb の構文解析のタイミングの差に起因します。 Ruby は......irb の起動時に --inspect オプションを指定する事でも同様の設定を行
えます。
$ irb --inspect [raw|p|pp|yaml|marshal|...]
上記以外にも独自の出力方式を追加する事ができます。詳しくは
IRB::Inspector.def_inspector を参照してください。...