るりまサーチ

最速Rubyリファレンスマニュアル検索!
156件ヒット [1-100件を表示] (0.048秒)
トップページ > クエリ:@[x] > クエリ:singleton_method[x]

別のキーワード

  1. singleton clone
  2. singleton dup
  3. singleton instance
  4. object define_singleton_method
  5. _builtin define_singleton_method

検索結果

<< 1 2 > >>

Object#singleton_method(name) -> Method (18161.0)

オブジェクトの特異メソッド name をオブジェクト化した Method オブ ジェクトを返します。

...す。

@
param name メソッド名をSymbol または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, Ob...

Object#define_singleton_method(symbol) { ... } -> Symbol (6132.0)

self に特異メソッド name を定義します。

...異メソッド name を定義します。

@
param symbol メソッド名を String または Symbol で指定します。

@
param method Proc、Method あるいは UnboundMethod の
いずれかのインスタンスを指定します。

@
return メソッド名を表す Symbol を返...
...t[][ruby]{
class A
class << self
def class_name
to_s
end
end
end
A.define_singleton_method(:who_am_i) do
"I am: #{class_name}"
end
A.who_am_i # ==> "I am: A"

guy = "Bob"
guy.define_singleton_method(:hello) { "#{self}: Hello there!" }
guy.hello #=> "Bob: Hello there!"
//}...

Object#define_singleton_method(symbol, method) -> Symbol (6132.0)

self に特異メソッド name を定義します。

...異メソッド name を定義します。

@
param symbol メソッド名を String または Symbol で指定します。

@
param method Proc、Method あるいは UnboundMethod の
いずれかのインスタンスを指定します。

@
return メソッド名を表す Symbol を返...
...t[][ruby]{
class A
class << self
def class_name
to_s
end
end
end
A.define_singleton_method(:who_am_i) do
"I am: #{class_name}"
end
A.who_am_i # ==> "I am: A"

guy = "Bob"
guy.define_singleton_method(:hello) { "#{self}: Hello there!" }
guy.hello #=> "Bob: Hello there!"
//}...

BasicObject#singleton_method_added(name) -> object (6131.0)

特異メソッドが追加された時にインタプリタから呼び出されます。

...ます。

@
param name 追加されたメソッド名が Symbol で渡されます。

//emlist[例][ruby]{
class Foo
def singleton_method_added(name)
puts "singleton method \"#{name}\" was added"
end
end

obj = Foo.new
def obj.foo
end

#=> singleton method "foo" was added
//}

@
see Module#m...
...ethod_added,BasicObject#singleton_method_removed,BasicObject#singleton_method_undefined...

BasicObject#singleton_method_removed(name) -> object (6131.0)

特異メソッドが Module#remove_method に より削除された時にインタプリタから呼び出されます。

...ソッドの削除に対するフックには
Module#method_removedを使います。

@
param name 削除されたメソッド名が Symbol で渡されます。

//emlist[例][ruby]{
class Foo
def singleton_method_removed(name)
puts "singleton method \"#{name}\" was removed"
end
end

obj =...
...Foo.new
def obj.foo
end

class << obj
remove_method :foo
end

#=> singleton method "foo" was removed
//}

@
see Module#method_removed,BasicObject#singleton_method_added,BasicObject#singleton_method_undefined...

絞り込み条件を変える

BasicObject#singleton_method_undefined(name) -> object (6131.0)

特異メソッドが Module#undef_method または undef により未定義にされた時にインタプリタから呼び出されます。

...の未定義に対するフックには
Module#method_undefined を使います。

@
param name 未定義にされたメソッド名が Symbol で渡されます。

//emlist[例][ruby]{
class Foo
def singleton_method_undefined(name)
puts "singleton method \"#{name}\" was undefined"
end
end...
...foo
end
def obj.bar
end

class << obj
undef_method :foo
end
obj.instance_eval {undef bar}

#=> singleton method "foo" was undefined
# singleton method "bar" was undefined
//}

@
see Module#method_undefined,BasicObject#singleton_method_added,BasicObject#singleton_method_removed , d:spec/def#undef...

Object#singleton_methods(inherited_too = true) -> [Symbol] (6112.0)

そのオブジェクトに対して定義されている特異メソッド名 (public あるいは protected メソッド) の一覧を返します。

...はスーパークラスのクラスメソッド(Classのインスタンスの特異メソッド)などです。

singleton_method
s(false) は、Object#methods(false) と同じです。

@
param inherited_too 継承した特異メソッドを含める場合は真を、
そうで...
...public; def public_self() end
end

# あるオブジェクトの特異メソッドの一覧を得る。
p obj.singleton_methods(false)
p obj.methods(false)
p Foo.singleton_methods(false)

#実行結果

[:protected_self, :public_self]
[:protected_self, :public_self]
[:protected_class_foo, :pub...
...ている。

p obj.singleton_methods(true)
p Foo.singleton_methods(true) - Object.singleton_methods(true)

#実行結果

[:protected_self, :public_self, :protected_bar, :public_bar]
[:protected_class_foo, :public_class_foo, :protected_class_parent, :public_class_parent]
//}

@
see Object#methods,Ob...

クラス/メソッドの定義 (82.0)

クラス/メソッドの定義 * クラス/メソッドの定義: * class * singleton_class * module * method * operator * nest_method * eval_method * singleton_method * class_method * limit * 定義に関する操作: * alias * undef * defined

.../メソッドの定義:
* class
* singleton_class
* module
* method
* operator
* nest_method
* eval_method
* singleton_method
* class_method
* limit
* 定義に関する操作:
* alias
* undef
* defined

===[a:class] クラス定義

//emlist[...
...@x, @yに対応するゲッタとセッタを定義
def initialize(x, y) # コンストラクタ
@
x = x; @y = y # @がつくのがインスタンス変数(メンバ変数)
end
def ==(other_vec) # いわゆる演算子オーバーライド
other_vec.x == @x && other_vec.y == @...
...y
end
def +(other_vec)
Vector2D.new(other_vec.x + @x, other_vec.y + @y)
end
# ...
end
vec0 = Vector2D.new(10, 20); vec1 = Vector2D.new(20, 30)
p vec0 + vec1 == Vector2D.new(30, 50) #=> true
//}

仮引数にデフォルト式が与えられた場合、メソッド呼び出しで実引数...

1.6.8から1.8.0への変更点(まとめ) (48.0)

1.6.8から1.8.0への変更点(まとめ) * ((<1.6.8から1.8.0への変更点(まとめ)/インタプリタの変更>)) * ((<1.6.8から1.8.0への変更点(まとめ)/追加されたクラス/モジュール>)) * ((<1.6.8から1.8.0への変更点(まとめ)/追加されたメソッド>)) * ((<1.6.8から1.8.0への変更点(まとめ)/追加された定数>)) * ((<1.6.8から1.8.0への変更点(まとめ)/拡張されたクラス/メソッド(互換性のある変更)>)) * ((<1.6.8から1.8.0への変更点(まとめ)/変更されたクラス/メソッド(互換性のない変更)>)) * ((<1.6.8から1.8.0への変更点(まとめ)/文法の変更>)) * ((<1.6.8から1.8.0への変更点(まとめ)/正規表現>)) * ((<1.6.8から1.8.0への変更点(まとめ)/Marshal>)) * ((<1.6.8から1.8.0への変更点(まとめ)/Windows 対応>)) * ((<1.6.8から1.8.0への変更点(まとめ)/廃止された(される予定の)機能>)) * ((<1.6.8から1.8.0への変更点(まとめ)/ライブラリ>)) * ((<1.6.8から1.8.0への変更点(まとめ)/拡張ライブラリAPI>)) * ((<1.6.8から1.8.0への変更点(まとめ)/バグ修正>)) * ((<1.6.8から1.8.0への変更点(まとめ)/サポートプラットフォームの追加>))

...することにより定数参照の速度を改善したそうです。
(ChangeLogの
Tue Jun 5 16:15:58 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
に該当するようです)

: break and next [compat]

break, next は、引数を指定することでイテレータや y...
...object_id|Object/object_id>)) [new]

追加 (Object#id は、obsolete)

: ((<Object#singleton_method_removed|Object/singleton_method_removed>)) [new]
: ((<Object#singleton_method_undefined|Object/singleton_method_undefined>)) [new]

追加

=== Proc

: ((<Proc#binding|Proc/binding>)) [new]...
...指定できるようになりました。((<RCR#146>))

: ((<Module#method_added|Module/method_added>)) [compat]
: ((<Module#singleton_method_added|Module/singleton_method_added>)) [compat]

拡張ライブラリからメソッドが定義されたときも呼ばれるようになりました。...
<< 1 2 > >>