ライブラリ
- ビルトイン (348)
-
minitest
/ spec (1) -
minitest
/ unit (1) - openssl (24)
- profiler (6)
- singleton (12)
- socket (12)
- win32ole (24)
モジュール
-
MiniTest
:: Assertions (1) -
Process
:: GID (24) -
Process
:: UID (24) - Singleton (12)
オブジェクト
- main (12)
キーワード
-
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (12) - < (12)
- <= (12)
- <=> (12)
- >= (12)
-
NEWS for Ruby 2
. 5 . 0 (8) -
NEWS for Ruby 3
. 0 . 0 (5) -
Profiler
_ _ (6) -
_ getproperty (12) -
_ invoke (12) - ancestors (12)
-
assert
_ includes (1) -
connect
_ nonblock (12) -
const
_ defined? (12) -
const
_ get (12) -
const
_ source _ location (12) - constants (12)
- extend (12)
- inspect (12)
- instance (12)
-
irb
/ completion (12) -
is
_ a? (12) -
kind
_ of? (12) - methods (12)
-
must
_ include (1) - new (24)
-
private
_ instance _ methods (12) -
private
_ methods (12) -
protected
_ methods (12) -
public
_ methods (12) - rdoc (12)
-
respond
_ to? (12) -
respond
_ to _ missing? (12) -
ruby 1
. 6 feature (12) -
ruby 1
. 8 . 4 feature (12) -
singleton
_ methods (12) - switch (48)
-
to
_ s (12) - クラス/メソッドの定義 (12)
検索結果
先頭5件
-
Module
# include(*mod) -> self (18279.0) -
モジュール mod をインクルードします。
...てしまうような include を行った場合に発生します。
//emlist[例][ruby]{
module M
end
module M2
include M
end
module M
include M2
end
//}
実行結果:
-:3:in `append_features': cyclic include detected (ArgumentError)
from -:3:in `include'
from -:3......重継承の代わりに用いられており、 mix-in とも呼びます。
//emlist[例][ruby]{
class C
include FileTest
include Math
end
p C.ancestors
# => [C, Math, FileTest, Object, Kernel]
//}
モジュールの機能追加は、クラスの継承関係の間にそのモジュール......同じモジュールを二回以上 include すると二回目以降は無視されます。
//emlist[例][ruby]{
module M
end
class C1
include M
end
class C2 < C1
include M # この include は無視される
end
p C2.ancestors # => [C2, C1, M, Object, Kernel]
//}
引数に複数のモ... -
main
. include(*modules) -> self (18235.0) -
引数 modules で指定したモジュールを後ろから順番に Object にインクルードします。
... Object にインクルードします。
@param modules Module のインスタンス( Enumerable など)を指定します。
@raise ArgumentError 継承関係が循環してしまうような include を行った場
合に発生します。
//emlist[例:][ruby]{
include Mat......h
hypot(3, 4) # => 5.0
//}
@see Module#include... -
Module
# >(other) -> bool | nil (18148.0) -
比較演算子。 self が other の先祖である場合、true を返します。 self が other の子孫か同一クラスである場合、false を返します。
...dule Included
include Awesome
end
module Prepended
prepend Awesome
end
Included.ancestors # => [Included, Awesome]
Awesome > Included # => true
Included > Awesome # => false
Prepended.ancestors # => [Awesome, Prepended]
Awesome > Prepended # => true
Prepended > Awesome # => false
Awesome > Aw......esome # => false
Awesome > Object # => nil
//}... -
Object
# must _ include(object) -> true (15314.0) -
自身に与えられたオブジェクトが含まれている場合、検査にパスしたことになります。
...ブジェクトが含まれている場合、検査にパスしたことになります。
@param object 任意のオブジェクトを指定します。
@raise MiniTest::Assertion 自身が include? メソッドを持たない場合に発生します。
自身に与え......られたオブジェクトが含まれていない場合に発生します。
@see MiniTest::Assertions#assert_includes... -
Object
# methods(include _ inherited = true) -> [Symbol] (9255.0) -
そのオブジェクトに対して呼び出せるメソッド名の一覧を返します。 このメソッドは public メソッドおよび protected メソッドの名前を返します。
...ected メソッドの名前を返します。
ただし特別に、引数が偽の時は Object#singleton_methods(false) と同じになっています。
@param include_inherited 引数が偽の時は Object#singleton_methods(false) と同じになります。
//emlist[例1][ruby]{
class Parent......指定して
# いるが、Object のインスタンスメソッドは一覧から排除している。
p obj.methods(true) - Object.instance_methods(true)
p obj.public_methods(true) - Object.public_instance_methods(true)
p obj.private_methods(true) - Object.private_instance_methods(t......rue)
p obj.protected_methods(true) - Object.protected_instance_methods(true)
# 実行結果
[:protected_singleton, :public_singleton, :protected_foo, :public_foo, :protected_parent, :public_parent]
[:public_singleton, :public_foo, :public_parent]
[:private_singleton, :private_foo, :private_parent]... -
Object
# respond _ to?(name , include _ all = false) -> bool (9225.0) -
オブジェクトがメソッド name を持つとき真を返します。
...します。
メソッドが定義されていない場合は、Object#respond_to_missing? を呼
び出してその結果を返します。
@param name Symbol または文字列で指定するメソッド名です。
@param include_all private メソッドと protected メソッドを確認の......"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?(:hello, true)")}
#=> Bonjour
# Guten Tag
module Template
def main
start
template_method
finish
end
de......end
end
class ImplTemplateMethod
include Template
def template_method
"implement template_method"
end
end
class NotImplTemplateMethod
include Template
# not implement template_method
end
puts ImplTemplateMethod.new.respond_to?(:template_method) # => true
# NotImplementedError が... -
Object
# respond _ to _ missing?(symbol , include _ private) -> bool (9225.0) -
自身が symbol で表されるメソッドに対し BasicObject#method_missing で反応するつもりならば真を返します。
...れるメソッドに対し
BasicObject#method_missing で反応するつもりならば真を返します。
Object#respond_to? はメソッドが定義されていない場合、
デフォルトでこのメソッドを呼びだし問合せます。
BasicObject#method_missing を override した......@param symbol メソッド名シンボル
@param include_private private method も含めたい場合に true が渡されます
//emlist[例][ruby]{
class Sample
def method_missing(name, *args)
if name =~ /^to_*/
[name, *args] # => [:to_sample, "sample args1", "sample args2"]
r......end
end
def respond_to_missing?(sym, include_private)
(sym =~ /^to_*/) ? true : super
end
end
s = Sample.new
s.to_sample("sample args1", "sample args2")
s.respond_to?(:to_sample) # => true
s.respond_to?(:sample) # => false
//}
@see Object#respond_to?, BasicObject#method_missing... -
Object
# private _ methods(include _ inherited = true) -> [Symbol] (9219.0) -
そのオブジェクトが理解できる private メソッド名の一覧を返します。
...が理解できる private メソッド名の一覧を返します。
@param include_inherited 偽となる値を指定すると自身のクラスのスーパークラスで定義されたメソッドを除きます。
@see Module#private_instance_methods,Object#methods,Object#singleton_methods... -
Object
# protected _ methods(include _ inherited = true) -> [Symbol] (9219.0) -
そのオブジェクトが理解できる protected メソッド名の一覧を返します。
...解できる protected メソッド名の一覧を返します。
@param include_inherited 偽となる値を指定すると自身のクラスのスーパークラスで定義されたメソッドを除きます。
@see Module#protected_instance_methods,Object#methods,Object#singleton_methods... -
Object
# public _ methods(include _ inherited = true) -> [Symbol] (9219.0) -
そのオブジェクトが理解できる public メソッド名の一覧を返します。
...が理解できる public メソッド名の一覧を返します。
@param include_inherited 偽となる値を指定すると自身のクラスのスーパークラスで定義されたメソッドを除きます。
@see Module#public_instance_methods,Object#methods,Object#singleton_methods...