110件ヒット
[1-100件を表示]
(0.399秒)
クラス
- Module (44)
- Object (22)
- UnboundMethod (44)
キーワード
- arity (11)
-
define
_ method (22) - inspect (11)
-
public
_ instance _ method (11) -
public
_ method (11) -
singleton
_ method (11) -
source
_ location (11) -
to
_ s (11)
検索結果
先頭5件
-
Module
# instance _ method(name) -> UnboundMethod (32251.0) -
self のインスタンスメソッド name をオブジェクト化した UnboundMethod を返します。
...Symbol または String で指定します。
@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 "; en......f do_e() print "!\n"; end
def do_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).c......all }
end
end
interpreter = Interpreter.new
interpreter.interpret('dave')
# => Hello there, Dave!
//}... -
Module
# public _ instance _ method(name) -> UnboundMethod (20227.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... -
UnboundMethod
# inspect -> String (14322.0) -
self を読みやすい文字列として返します。
...self を読みやすい文字列として返します。
詳しくは Method#inspect を参照してください。
//emlist[例][ruby]{
String.instance_method(:count).inspect # => "#<UnboundMethod: String#count>"
//}
@see Method#inspect... -
UnboundMethod
# source _ location -> [String , Integer] | nil (14215.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... -
UnboundMethod
# arity -> Integer (14186.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 #=>... -
Module
# define _ method(name) { . . . } -> Symbol (14114.0) -
インスタンスメソッド name を定義します。
...定義したメソッドの実行時にブロックが
レシーバクラスのインスタンスの上で BasicObject#instance_eval されます。
@param name メソッド名を String または Symbol を指定します。
@param method Proc、Method あるいは UnboundMethod の
いず......ol を返します。
@raise TypeError method に同じクラス、サブクラス、モジュール以外のメソッ
ドを指定した場合に発生します。
//emlist[例][ruby]{
class Foo
def foo() p :foo end
define_method(:bar, instance_method(:foo))
end
Foo.new.bar... -
Module
# define _ method(name , method) -> Symbol (14114.0) -
インスタンスメソッド name を定義します。
...定義したメソッドの実行時にブロックが
レシーバクラスのインスタンスの上で BasicObject#instance_eval されます。
@param name メソッド名を String または Symbol を指定します。
@param method Proc、Method あるいは UnboundMethod の
いず......ol を返します。
@raise TypeError method に同じクラス、サブクラス、モジュール以外のメソッ
ドを指定した場合に発生します。
//emlist[例][ruby]{
class Foo
def foo() p :foo end
define_method(:bar, instance_method(:foo))
end
Foo.new.bar... -
Object
# public _ method(name) -> Method (14114.0) -
オブジェクトの public メソッド name をオブジェクト化した Method オブジェクトを返します。
...トの public メソッド name をオブジェクト化した
Method オブジェクトを返します。
@param name メソッド名を Symbol または String で指定します。
@raise NameError 定義されていないメソッド名や、
protected メソッド名、 private メソ......ッド名を引数として与えると発生します。
//emlist[][ruby]{
1.public_method(:to_int) #=> #<Method: Integer#to_int>
1.public_method(:p) # method `p' for class `Integer' is private (NameError)
//}
@see Object#method,Object#public_send,Module#public_instance_method... -
Object
# singleton _ method(name) -> Method (14114.0) -
オブジェクトの特異メソッド name をオブジェクト化した Method オブ ジェクトを返します。
...はStringで指定します。
@raise NameError 定義されていないメソッド名を引数として与えると発生します。
//emlist[][ruby]{
class Demo
def initialize(n)
@iv = n
end
def hello()
"Hello, @iv = #{@iv}"
end
end
k = Demo.new(99)
def k.hi
"Hi, @iv = #{@iv}......"
end
m = k.singleton_method(:hi) # => #<Method: #<Demo:0xf8b0c3c4 @iv=99>.hi>
m.call #=> "Hi, @iv = 99"
m = k.singleton_method(:hello) # => NameError
//}
@see Module#instance_method, Method, BasicObject#__send__, Object#send, Kernel.#eval, Object#method... -
UnboundMethod
# to _ s -> String (11222.0) -
self を読みやすい文字列として返します。
...self を読みやすい文字列として返します。
詳しくは Method#inspect を参照してください。
//emlist[例][ruby]{
String.instance_method(:count).inspect # => "#<UnboundMethod: String#count>"
//}
@see Method#inspect...