別のキーワード
クラス
- BasicObject (48)
- Binding (70)
- Module (96)
- Object (78)
- Proc (24)
-
RubyVM
:: InstructionSequence (24) - String (12)
- TracePoint (26)
-
WIN32OLE
_ TYPE (12)
キーワード
- binding (12)
-
class
_ eval (24) -
class
_ exec (12) -
default
_ event _ sources (12) -
define
_ method (24) - dump (12)
-
eval
_ script (7) -
instance
_ eval (24) -
instance
_ exec (12) -
instance
_ variables (12) -
instruction
_ sequence (7) -
local
_ variable _ defined? (12) -
local
_ variable _ get (12) -
local
_ variable _ set (12) -
local
_ variables (11) - method (12)
-
module
_ eval (24) -
module
_ exec (12) - receiver (11)
-
respond
_ to? (12) - self (12)
- send (24)
-
singleton
_ method (12) -
singleton
_ method _ undefined (12) -
source
_ location (12) - taint (6)
-
to
_ a (12)
検索結果
先頭5件
-
Module
# module _ eval {|mod| . . . } -> object (6173.0) -
モジュールのコンテキストで文字列 expr またはモジュール自身をブロックパラメータとするブロックを 評価してその結果を返します。
...。
つまり、そのモジュールの定義式の中にあるかのように実行されます。
ただし、ローカル変数は module_eval/class_eval の外側のスコープと共有します。
定数とクラス変数のスコープは、文字列が与えられた場合とブロック......とができます。
//emlist[例][ruby]{
class C
end
a = 1
C.class_eval %Q{
def m # メソッドを動的に定義できる。
return :m, #{a}
end
}
p C.new.m #=> [:m, 1]
//}
//emlist[定数のスコープが異なる例][ruby]{
class C
end
# ブロックが渡......s_eval { X = 1 }
# 文字列が渡された場合は、モジュール定義式内と同じスコープになる。つまり、この場合は
# class C
# X = 2
# end
# と書いたのと同じ意味になる。
C.class_eval 'X = 2'
p X #=> 1
p C::X #=> 2
//}
@see BasicObject#instance_eval,... -
TracePoint
# eval _ script -> String | nil (6126.0) -
script_compiledイベント発生時にコンパイルされたソースコードを返します。 ファイルから読み込んだ場合は、nilを返します。
...します。
ファイルから読み込んだ場合は、nilを返します。
//emlist[例][ruby]{
TracePoint.new(:script_compiled) do |tp|
p tp.eval_script # => "puts 'hello'"
end.enable do
eval("puts 'hello'")
end
//}
@raise RuntimeError :script_compiled イベントのための... -
TracePoint
# instruction _ sequence -> RubyVM :: InstructionSequence (225.0) -
script_compiledイベント発生時にコンパイルされた RubyVM::InstructionSequenceインスタンスを返します。
...時にコンパイルされた
RubyVM::InstructionSequenceインスタンスを返します。
//emlist[例][ruby]{
TracePoint.new(:script_compiled) do |tp|
p tp.instruction_sequence # => <RubyVM::InstructionSequence:block in <main>@(eval):1>
end.enable do
eval("puts 'hello'")
end
//}
@raise R... -
Object
# taint -> self (101.0) -
このメソッドは Ruby 2.7 から deprecated で、Ruby 3.2 で削除予定です。
...このメソッドは Ruby 2.7 から deprecated で、Ruby 3.2 で削除予定です。
オブジェクトの「汚染マーク」をセットします。
環境変数(ENVで得られる文字列)など一部のオブジェクトは最初から汚染されています。
オブジェクト......照してください。
//emlist[][ruby]{
$SAFE = 1
some = "puts '@&%&(#!'"
p some.tainted? #=> false
eval(some) #=> @&%&(#!
some.taint
p some.tainted? #=> true
eval(some) # Insecure operation - eval (SecurityError)
some.untaint
p some.tainted? #=> false
eval(some) #=> @&%&(#!
p ENV['OS'].tain... -
WIN32OLE
_ TYPE # default _ event _ sources -> [WIN32OLE _ TYPE] (79.0) -
型が持つソースインターフェイスを取得します。
...class WebEvent
def initialize
@completed = false
end
attr_reader :completed
end
source.ole_methods.each do |m|
WebEvent.module_eval do
define_method("on#{m.name}") do |*arg|
if arg[0] == "ページが表示されました"
@completed = true
end......now}: #{m.name} was called"
p arg
end
end
end
evt = WIN32OLE_EVENT.new(ctl)
evt.handler = WebEvent.new
ctl.navigate2 'http://www.ruby-lang.org/'
loop do
break if evt.handler.completed
WIN32OLE_EVENT.message_loop
end
ctl.Quit
このプログラムを実行するとWindows......e was called
["{265b75c1-4158-11d0-90f6-00c04fd497ea}"]
2010-10-06 22:33:54 +0900: BeforeNavigate2 was called
[#<WIN32OLE:0x9d08f0>, "http://www.ruby-lang.org/", 0, "", nil, "", false]
2010-10-06 22:33:54 +0900: DownloadBegin was called
[]
2010-10-06 22:33:54 +0900: PropertyChange was called... -
Object
# respond _ to?(name , include _ all = false) -> bool (55.0) -
オブジェクトがメソッド name を持つとき真を返します。
...します。
※ NotImplementedError が発生する場合に false を返すのは
Rubyの組み込みライブラリや標準ライブラリなど、C言語で実装されているメソッドのみです。
Rubyで実装されたメソッドで NotImplementedError が発生する場合は true......事になります。
//emlist[][ruby]{
class F
def hello
"Bonjour"
end
end
class D
private
def hello
"Guten Tag"
end
end
list = [F.new,D.new]
list.each{|it| puts it.hello if it.respond_to?(:hello)}
#=> Bonjour
list.each{|it| it.instance_eval("puts hello if it.respond_to?(:hell......implement template_method
end
puts ImplTemplateMethod.new.respond_to?(:template_method) # => true
# NotImplementedError が発生しているが、Rubyによる実装部のため true を返す
puts NotImplTemplateMethod.new.respond_to?(:template_method) # => true
# GNU/Linux で実行。C言語に... -
Binding
# local _ variable _ set(symbol , obj) (43.0) -
引数 symbol で指定した名前のローカル変数に引数 obj を設定します。
...指定します。
@param obj 引数 symbol で指定したローカル変数に設定するオブジェクトを指定します。
//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......# => NameError
end
//}
このメソッドは以下のコード(ただし、obj が Ruby のコードで出力される場
合)と同様の動作をします。
//emlist[][ruby]{
binding.eval("#{symbol} = #{obj}")
//}
@see Binding#local_variable_get, Binding#local_variable_defined?... -
Object
# send(name , *args) -> object (43.0) -
オブジェクトのメソッド name を args を引数に して呼び出し、メソッドの実行結果を返します。
...l で指定するメソッド名です。
@param args 呼び出すメソッドに渡す引数です。
//emlist[][ruby]{
p -365.send(:abs) #=> 365
p "ruby".send(:sub,/./,"R") #=> "Ruby"
class Foo
def foo() "foo" end
def bar() "bar" end
def baz() "baz" end
end
# 任意のキーとメソッ......ーバは任意(Foo クラスのインスタンスである必要もない)
p Foo.new.send(methods[1]) # => "foo"
p Foo.new.send(methods[2]) # => "bar"
p Foo.new.send(methods[3]) # => "baz"
//}
@see Object#public_send, BasicObject#__send__, Object#method, Kernel.#eval, Proc, Method... -
Object
# send(name , *args) { . . . . } -> object (43.0) -
オブジェクトのメソッド name を args を引数に して呼び出し、メソッドの実行結果を返します。
...l で指定するメソッド名です。
@param args 呼び出すメソッドに渡す引数です。
//emlist[][ruby]{
p -365.send(:abs) #=> 365
p "ruby".send(:sub,/./,"R") #=> "Ruby"
class Foo
def foo() "foo" end
def bar() "bar" end
def baz() "baz" end
end
# 任意のキーとメソッ......ーバは任意(Foo クラスのインスタンスである必要もない)
p Foo.new.send(methods[1]) # => "foo"
p Foo.new.send(methods[2]) # => "bar"
p Foo.new.send(methods[3]) # => "baz"
//}
@see Object#public_send, BasicObject#__send__, Object#method, Kernel.#eval, Proc, Method... -
Proc
# source _ location -> [String , Integer] | nil (37.0) -
ソースコードのファイル名と行番号を配列で返します。
...が ruby で定義されていない(つまりネイティブ
である)場合は nil を返します。
//emlist[例][ruby]{
# /path/to/target.rb を実行
proc {}.source_location # => ["/path/to/target.rb", 1]
proc {}.source_location # => ["/path/to/target.rb", 2]
(eval "pr......oc {}").source_location # => ["(eval)", 1]
method(:p).to_proc.source_location # => nil
//}
@see Method#source_location...