種類
- インスタンスメソッド (98)
- 文書 (64)
- 特異メソッド (44)
- モジュール関数 (44)
- ライブラリ (33)
クラス
- Binding (54)
- ERB (11)
- Proc (11)
-
RubyVM
:: InstructionSequence (11) - Thread (22)
- TracePoint (11)
- Tracer (22)
モジュール
- Kernel (22)
- ObjectSpace (22)
キーワード
-
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (11) -
NEWS for Ruby 2
. 1 . 0 (11) -
NEWS for Ruby 2
. 7 . 0 (5) -
NEWS for Ruby 3
. 0 . 0 (4) -
add
_ filter (22) - backtrace (11)
-
define
_ finalizer (22) - eval (22)
- irb (11)
-
irb
/ xmp (11) -
local
_ variable _ defined? (11) -
local
_ variable _ get (11) -
local
_ variable _ set (11) -
local
_ variables (10) - new (11)
- of (11)
-
ruby 1
. 6 feature (11) -
ruby 1
. 8 . 4 feature (11) -
ruby 1
. 9 feature (11) -
set
_ trace _ func (11) - tracer (11)
検索結果
先頭5件
-
TracePoint
# binding -> Binding | nil (33642.0) -
発生したイベントによって生成された Binding オブジェクトを返します。
...れた Binding オブジェクトを返します。
C で記述されたメソッドは binding を生成しないため、
:c_call および :c_return イベントに対しては nil を返すことに注意してください。
//emlist[例][ruby]{
def foo(ret)
ret
end
trace = TracePoint.new(:......call) do |tp|
p tp.binding.local_variables # => [:ret]
end
trace.enable
foo 1
//}... -
TracePoint
# binding -> Binding (33636.0) -
発生したイベントによって生成された Binding オブジェクトを返します。
...発生したイベントによって生成された Binding オブジェクトを返します。
//emlist[例][ruby]{
def foo(ret)
ret
end
trace = TracePoint.new(:call) do |tp|
p tp.binding.local_variables # => [:ret]
end
trace.enable
foo 1
//}... -
Kernel
. # binding -> Binding (30636.0) -
変数・メソッドなどの環境情報を含んだ Binding オブジェクトを 生成して返します。通常、Kernel.#eval の第二引数として使います。
...変数・メソッドなどの環境情報を含んだ Binding オブジェクトを
生成して返します。通常、Kernel.#eval の第二引数として使います。
//emlist[例][ruby]{
def foo
a = 1
binding
end
eval("p a", foo) #=> 1
//}
@see Kernel.#eval,Object::TOPLEVEL_BINDING... -
Proc
# binding -> Binding (30630.0) -
Proc オブジェクトが保持するコンテキストを Binding オブジェクトで返します。
...Proc オブジェクトが保持するコンテキストを
Binding オブジェクトで返します。
//emlist[例][ruby]{
def fred(param)
proc {}
end
sample_proc = fred(99)
eval("param", sample_proc.binding) # => 99
//}... -
irb (26168.0)
-
irb は Interactive Ruby の略です。 irb を使うと、Ruby の式を標準入力から簡単に入力・実行することができます。
...irb は Interactive Ruby の略です。
irb を使うと、Ruby の式を標準入力から簡単に入力・実行することができます。
=== irb の使い方
Ruby さえ知っていれば irb を使うのは簡単です。
irb コマンドを実行すると、以下のようなプロン......$ irb
irb(main):001:0>
あとは Ruby の式を入力するだけで、その式が実行され、結果が表示されます。
irb(main):001:0> 1+2
3
irb(main):002:0> class Foo
irb(main):003:1> def foo
irb(main):004:2> print 1
irb(main):005:2> end
irb(main):006:1> end......--back-trace-limit n
バックトレース表示をバックトレースの頭から n、
うしろから n だけ行なう。デフォルト値は 16。
--context-mode n 新しいワークスペースを作成した時に関連する Binding... -
irb
/ xmp (26048.0) -
Ruby のソースコードとその実行結果を、行ごとに交互に表示するためのライブ ラリです。irb を実行しなくても、使用することが出来ます。
...irb を実行しなくても、使用することが出来ます。
実行結果を得るためには、Kernel#xmp と、XMP#puts を使った方
法があります。どちらの場合も XMP がコンテキスト情報を保持するため、
実行結果に差分はありません。(Binding......by のソースコードを文字列として渡
す事で実行結果を標準出力に表示します。
$ cat t.rb
require "irb/xmp"
xmp <<END
foo = 1
foo
END
$ ruby t.rb
foo = 1
==>1
foo
==>1
=== XMP インスタンス(XMP#puts)を使って実行結果を得る
X......文字列として渡す
事で実行結果を標準出力に表示します。
$ cat t.rb
require "irb/xmp"
xmp = XMP.new
xmp.puts <<END
foo = 1
foo
END
xmp.puts <<END
foo
END
$ ruby t.rb
foo = 1
==>1
foo
==>1
foo
==>1
XMP がコンテキスト情報... -
Binding
# local _ variable _ defined?(symbol) -> bool (21136.0) -
引数 symbol で指定した名前のローカル変数が定義されている場合に true を、 そうでない場合に false を返します。
...//emlist[例][ruby]{
def foo
a = 1
binding.local_variable_defined?(:a) # => true
binding.local_variable_defined?(:b) # => false
end
//}
このメソッドは以下のコードの短縮形です。
//emlist[][ruby]{
binding.eval("defined?(#{symbol}) == 'local-variable'")
//}
@see Binding#loc......al_variable_get, Binding#local_variable_set... -
Binding
# local _ variable _ get(symbol) -> object (18136.0) -
引数 symbol で指定した名前のローカル変数に設定された値を返します。
...クトで指定します。
@raise NameError 引数 symbol で指定したローカル変数が未定義の場合に発生します。
//emlist[例][ruby]{
def foo
a = 1
binding.local_variable_get(:a) # => 1
binding.local_variable_get(:b) # => NameError
end
//}
このメソッドは以下......のコードの短縮形です。
//emlist[][ruby]{
binding.eval("#{symbol}")
//}
@see Binding#local_variable_set, Binding#local_variable_defined?... -
Binding
# local _ variable _ set(symbol , obj) (18136.0) -
引数 symbol で指定した名前のローカル変数に引数 obj を設定します。
...//emlist[例][ruby]{
def foo
a = 1
bind = binding
bind.local_variable_set(:a, 2) # set existing local variable `a'
bind.local_variable_set(:b, 3) # create new local variable `b'
# `b' exists only in binding
p bind.local_variable_get(:a) # => 2
p bind.lo......cal_variable_get(:b) # => 3
p a # => 2
p b # => NameError
end
//}
このメソッドは以下のコード(ただし、obj が Ruby のコードで出力される場
合)と同様の動作をします。
//emlist[][ruby]{
binding.eval("#{sy......mbol} = #{obj}")
//}
@see Binding#local_variable_get, Binding#local_variable_defined?... -
Binding
# local _ variables -> [Symbol] (18124.0) -
ローカル変数の一覧を Symbol の配列で返します。
...カル変数の一覧を Symbol の配列で返します。
//emlist[例][ruby]{
def foo
a = 1
2.times do |n|
binding.local_variables #=> [:a, :n]
end
end
//}
このメソッドは以下のコードと同様の動作をします。
//emlist[][ruby]{
binding.eval("local_variables")
//}... -
Binding
# eval(expr , fname = _ _ FILE _ _ , lineno = 1) -> object (15124.0) -
自身をコンテキストとし文字列 expr を Ruby プログラムとして評価しその結果を返します。 組み込み関数 Kernel.#eval を使って eval(expr, self, fname, lineno) とするのと同じです。
...(expr, self, fname, lineno) とするのと同じです。
@param expr 評価したい式を文字列で与えます。
@param fname ファイル名を文字列で与えます。式 expr が fname というファイル名にあるかのように実行されます。
@param lineno 行番号を整......えます。式 expr の先頭行の行番号が lineno であるかのように実行されます。
//emlist[例][ruby]{
def get_binding(str)
binding
end
str = "hello"
p eval("str + ' Fred'") #=> "hello Fred"
p get_binding("bye").eval("str + ' Fred'") #=> "bye Fred"
//}...