186件ヒット
[1-100件を表示]
(0.405秒)
クラス
- Module (88)
- Object (22)
- UnboundMethod (76)
キーワード
- arity (11)
- bind (11)
-
bind
_ call (10) -
define
_ method (22) - inspect (11)
-
instance
_ methods (11) -
original
_ name (11) -
private
_ instance _ methods (11) -
protected
_ instance _ methods (11) -
public
_ instance _ method (11) -
public
_ instance _ methods (11) -
public
_ method (11) -
singleton
_ method (11) -
source
_ location (11) -
to
_ s (11)
検索結果
先頭5件
-
Module
# instance _ method(name) -> UnboundMethod (32233.0) -
self のインスタンスメソッド name をオブジェクト化した UnboundMethod を返します。
...tring で指定します。
@raise NameError self に存在しないメソッドを指定した場合に発生します。
@see Module#public_instance_method, Object#method
//emlist[例][ruby]{
class Interpreter
def do_a() print "there, "; end
def do_d() print "Hello "; end
def do_e() prin......_v() print "Dave"; end
Dispatcher = {
"a" => instance_method(:do_a),
"d" => instance_method(:do_d),
"e" => instance_method(:do_e),
"v" => instance_method(:do_v)
}
def interpret(string)
string.each_char {|b| Dispatcher[b].bind(self).call }
end
end
interpreter = Interpr......eter.new
interpreter.interpret('dave')
# => Hello there, Dave!
//}... -
Module
# instance _ methods(inherited _ too = true) -> [Symbol] (20302.0) -
そのモジュールで定義されている public および protected メソッド名 の一覧を配列で返します。
...いる public および protected メソッド名
の一覧を配列で返します。
@param inherited_too false を指定するとそのモジュールで定義されているメソッドのみ返します。
@see Object#methods
//emlist[例1][ruby]{
class Foo
private; def private_foo() e......def protected_foo() end
public; def public_foo() end
end
# あるクラスのインスタンスメソッドの一覧を得る
p Foo.instance_methods(false)
p Foo.public_instance_methods(false)
p Foo.private_instance_methods(false)
p Foo.protected_instance_methods(false)
class Bar < Foo
end......//}
実行結果
[:protected_foo, :public_foo]
[:public_foo]
[:private_foo]
[:protected_foo]
//emlist[例2][ruby]{
class Bar
private; def private_foo() end
protected; def protected_foo() end
public; def public_foo() end
end
# あるクラスのインスタン... -
Module
# protected _ instance _ methods(inherited _ too = true) -> [Symbol] (20302.0) -
そのモジュールで定義されている protected メソッド名 の一覧を配列で返します。
...そのモジュールで定義されている protected メソッド名
の一覧を配列で返します。
@param inherited_too false を指定するとそのモジュールで定義されているメソッドのみ返します。
@see Object#protected_methods, Module#instance_methods... -
Module
# public _ instance _ method(name) -> UnboundMethod (20221.0) -
self の public インスタンスメソッド name をオブジェクト化した UnboundMethod を返します。
...の public インスタンスメソッド name をオブジェクト化した UnboundMethod を返します。
@param name メソッド名を Symbol または String で指定します。
@raise NameError 定義されていないメソッド名や、
protected メソッド名、 private メ......として与えると発生します。
//emlist[例][ruby]{
Kernel.public_instance_method(:object_id) #=> #<UnboundMethod: Kernel#object_id>
Kernel.public_instance_method(:p) # method `p' for module `Kernel' is private (NameError)
//}
@see Module#instance_method,Object#public_method... -
Module
# private _ instance _ methods(inherited _ too = true) -> [Symbol] (20202.0) -
そのモジュールで定義されている private メソッド名 の一覧を配列で返します。
...private メソッド名
の一覧を配列で返します。
@param inherited_too false を指定するとそのモジュールで定義されているメソッドのみ返します。
@see Object#private_methods, Module#instance_methods
//emlist[例][ruby]{
module Foo
def foo; end
private d......ef bar; end
end
module Bar
include Foo
def baz; end
private def qux; end
end
Bar.private_instance_methods # => [:qux, :bar]
Bar.private_instance_methods(false) # => [:qux]
//}... -
Module
# public _ instance _ methods(inherited _ too = true) -> [Symbol] (20202.0) -
そのモジュールで定義されている public メソッド名 の一覧を配列で返します。
...そのモジュールで定義されている public メソッド名
の一覧を配列で返します。
@param inherited_too false を指定するとそのモジュールで定義されているメソッドのみ返します。
@see Object#public_methods, Module#instance_methods... -
UnboundMethod
# inspect -> String (14208.0) -
self を読みやすい文字列として返します。
...self を読みやすい文字列として返します。
詳しくは Method#inspect を参照してください。
//emlist[例][ruby]{
String.instance_method(:count).inspect # => "#<UnboundMethod: String#count>"
//}
@see Method#inspect... -
UnboundMethod
# arity -> Integer (14162.0) -
メソッドが受け付ける引数の数を返します。
...list[例][ruby]{
class C
def one; end
def two(a); end
def three(*a); end
def four(a, b); end
def five(a, b, *c); end
def six(a, b, *c, &d); end
end
p C.instance_method(:one).arity #=> 0
p C.instance_method(:two).arity #=> 1
p C.instance_method(:three).arity #=> -1
p C.i......od(:four).arity #=> 2
p C.instance_method(:five).arity #=> -3
p C.instance_method(:six).arity #=> -3
String.instance_method(:size).arity #=> 0
String.instance_method(:replace).arity #=> 1
String.instance_method(:squeeze).arity #=> -1
String.instance_method(:count).arity #=>... -
UnboundMethod
# bind(obj) -> Method (14114.0) -
self を obj にバインドした Method オブジェクトを生成して返します。
...す。
@raise TypeError objがbindできないオブジェクトである場合に発生します
//emlist[例][ruby]{
# クラスのインスタンスメソッドの UnboundMethod の場合
class Foo
def foo
"foo"
end
end
# UnboundMethod `m' を生成
p m = Foo.instance_method(:foo) # =>......スをレシーバとする Method オブジェクトを生成
p m.bind(Foo.new) # => #<Method: Foo#foo>
# Foo のサブクラス Bar のインスタンスをレシーバとする Method
class Bar < Foo
end
p m.bind(Bar.new) # => #<Method: Bar(Foo)#foo>
# モジュー......# UnboundMethod `m' を生成
p m = Foo.instance_method(:foo) # => #<UnboundMethod: Foo#foo>
# Foo をインクルードしたクラス Bar のインスタンスをレシーバと
# する Method オブジェクトを生成
class Bar
include Foo
end
p m.bind(Bar.new) # => #<Method:......instance_method(:foo) # => #<UnboundMethod: Foo#foo>
# Foo をインクルードしたクラス Bar のインスタンスをレシーバと
# する Method オブジェクトを生成
class Bar
include Foo
end
p m.bind(Bar.new) # => #<Method: Bar(Foo)#foo>
//}
@see UnboundMethod#bi... -
UnboundMethod
# source _ location -> [String , Integer] | nil (14114.0) -
ソースコードのファイル名と行番号を配列で返します。
...nil を返します。
//emlist[例][ruby]{
require 'time'
Time.instance_method(:zone).source_location # => nil
Time.instance_method(:httpdate).source_location # => ["/Users/user/.rbenv/versions/2.4.3/lib/ruby/2.4.0/time.rb", 654]
//}
@see Proc#source_location, Method#source_location...