関連するキーワード
ライブラリ
- ビルトイン (24)
キーワード
- <= (3)
- <=> (3)
- ancestors (3)
- include (3)
- include? (3)
-
instance
_ methods (3) -
undef
_ method (3)
検索結果
先頭5件
-
Module
# <(other) -> bool | nil (18137) -
比較演算子。self が other の子孫である場合、 true を返します。 self が other の先祖か同一のクラス/モジュールである場合、false を返します。
...
module Foo
end
class Bar
include Foo
end
class Baz < Bar
end
class Qux
end
p Bar < Foo # => true
p Baz < Bar # => true
p Baz < Foo # => true
p Baz < Qux # => nil
p Baz > Qux # => nil
p Foo < Object.new # => in `<': compared with non class/module... -
Module
# <=>(other) -> Integer | nil (6107) -
self と other の継承関係を比較します。
...ラスやモジュール
module Foo
end
class Bar
include Foo
end
class Baz < Bar
end
class Qux
end
p Bar <=> Foo # => -1
p Baz <=> Bar # => -1
p Baz <=> Foo # => -1
p Baz <=> Qux # => nil
p Qux <=> Baz # => nil
p Baz <=> Object.new # => nil... -
Module
# <=(other) -> bool | nil (6101) -
比較演算子。self が other の子孫であるか、self と other が 同一クラスである場合、 true を返します。 self が other の先祖である場合、false を返します。
...ther の先祖である場合、false を返します。
継承関係にないクラス同士の比較では
nil を返します。
@param other 比較対象のモジュールやクラス
@raise TypeError other がクラスやモジュールではない場合に発生します。
@see Module#<... -
Module
# ancestors -> [Class , Module] (7) -
クラス、モジュールのスーパークラスとインクルードしているモジュール を優先順位順に配列に格納して返します。
...ル
を優先順位順に配列に格納して返します。
module Foo
end
class Bar
include Foo
end
class Baz < Bar
p ancestors
p included_modules
p superclass
end
# => [Baz, Bar, Foo, Object, Kernel]
# => [Foo, Kernel]
# => Bar
@see Module#included_modules... -
Module
# include(*mod) -> self (7) -
モジュール mod をインクルードします。
...ドします。
@param mod Module のインスタンス( Enumerable など)を指定します。
@raise ArgumentError 継承関係が循環してしまうような include を行った場合に発生します。
module M
end
module M2
include M
end
module M
include M2
end
実......先に行われます
(上の例の Module#ancestors の結果がメソッド探索の順序です)。
同じモジュールを二回以上 include すると二回目以降は無視されます。
module M
end
class C1
include M
end
class C2 < C1
include M # この include は... -
Module
# include?(mod) -> bool (7) -
self かその親クラス / 親モジュールがモジュール mod を インクルードしていれば true を返します。
...その親クラス / 親モジュールがモジュール mod を
インクルードしていれば true を返します。
@param mod Module を指定します。
module M
end
class C1
include M
end
class C2 < C1
end
p C1.include?(M) # => true
p C2.include?(M) # => true... -
Module
# instance _ methods(inherited _ too = true) -> [String] (7) -
そのモジュールで定義されている public および protected メソッド名 の一覧を配列で返します。
..._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"]
例2:
class Bar... -
Module
# instance _ methods(inherited _ too = true) -> [Symbol] (7) -
そのモジュールで定義されている public および protected メソッド名 の一覧を配列で返します。
..._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]
例2:
class Bar
pri... -
Module
# undef _ method(*name) -> self (7) -
このモジュールのインスタンスメソッド name を未定義にします。
...削除」とは区別されます。
以下のコード例を参照してください。
class A
def ok
puts 'A'
end
end
class B < A
def ok
puts 'B'
end
end
B.new.ok # => B
# undef_method の場合はスーパークラスに同名のメソッドがあっ......名を String または Symbol で与えられることです。
module M1
def foo
end
def self.moo
undef foo
end
end
M1.instance_methods false #=> ["foo"]
M1.moo
M1.instance_methods false #=> []
module M2
def foo
end
def self.moo
undef_method :fo...
