るりまサーチ

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

別のキーワード

  1. optparse on
  2. optionparser on
  3. tracer on
  4. thread abort_on_exception
  5. _builtin abort_on_exception

検索結果

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

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

..."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__, Ob...

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

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

...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#method_added,BasicObject#singleton_method_removed,BasicObject#singleton_method_undefined...

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

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

...f 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...

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

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

...class Foo
def singleton_method_undefined(name)
puts "singleton method \"#{name}\" was undefined"
end
end

obj = Foo.new
def obj.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" wa...
...s undefined
//}

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

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

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

...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 (12314.0)

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

...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#singleton_methods(inherited_too = true) -> [Symbol] (12306.0)

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

...self がクラスの場合はスーパークラスのクラスメソッド(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...
...よう true を指定したが、
# Object のクラスメソッドは一覧から排除している。

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, :p...

1.6.8から1.8.0への変更点(まとめ) (2562.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への変更点(まとめ)/サポートプラットフォームの追加>))

...作はなくなりました)

$defout や $deferr に代入を行うと警告がでます。
(注:1.6 に $deferr はありません)
((<ruby-dev:20961>))

$stdin にオブジェクトを代入すると標準入力からの入力メソッド(gets 等)
はそのオブジェクトにメソ...
...変更されました。((<ruby-dev:20358>))

* Proc.new およびブロック引数で与えられる Proc は
引数チェックがゆるい。break が例外になる。

Proc.new {|a,b,c| p [a,b,c]}.call(1,2)
=> -:1: wrong # of arguments (2 for 3) (Argum...
...Object#singleton_method_removed|Object/singleton_method_removed>)) [new]
: ((<Object#singleton_method_undefined|Object/singleton_method_undefined>)) [new]

追加

=== Proc

: ((<Proc#binding|Proc/binding>)) [new]

追加

: ((<Proc#to_proc|Proc/to_proc>)) [new]

追加

# : ((<Precision>)).in...