るりまサーチ

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

別のキーワード

  1. module included_modules
  2. context modules
  3. stats num_modules
  4. stats num_modules=
  5. _builtin included_modules

ライブラリ

クラス

オブジェクト

検索結果

main.include(*modules) -> self (18242.0)

引数 modules で指定したモジュールを後ろから順番に Object にインクルードします。

...引数 modules で指定したモジュールを後ろから順番に Object にインクルードします。

@param modules Module のインスタンス( Enumerable など)を指定します。

@raise ArgumentError 継承関係が循環してしまうような include を行った場...
...合に発生します。

//emlist[例:][ruby]{
include
Math

hypot(3, 4) # => 5.0
//}

@see Module#include...

Module#included_modules -> [Module] (12219.0)

self にインクルードされているモジュールの配列を返します。

...self にインクルードされているモジュールの配列を返します。

//emlist[例][ruby]{
module Mixin
end

module Outer
include
Mixin
end

Mixin.included_modules #=> []
Outer.included_modules #=> [Mixin]
//}

@see Module#ancestors...

VALUE rb_mod_included_modules(VALUE mod) (12200.0)

モジュール mod にインクルードされているモジュールの配列を返します。

モジュール mod にインクルードされているモジュールの配列を返します。

Object#extend(*modules) -> self (137.0)

引数で指定したモジュールのインスタンスメソッドを self の特異 メソッドとして追加します。

...引数で指定したモジュールのインスタンスメソッドを self の特異
メソッドとして追加します。

Module#include は、クラス(のインスタンス)に機能を追加します
が、extend は、ある特定のオブジェクトだけにモジュールの機能を...
...に使用します。

引数に複数のモジュールを指定した場合、最後
の引数から逆順に extend を行います。

@param modules モジュールを任意個指定します(クラスは不可)。
@return self を返します。

//emlist[][ruby]{
module Foo
def a
'o...
....extend Foo, Bar
p obj.a #=> "ok Foo"
p obj.b #=> "ok Bar"

class Klass
include
Foo
extend Bar
end

p Klass.new.a #=> "ok Foo"
p Klass.b #=> "ok Bar"
//}

extend の機能は、「特異クラスに対する Module#include
と言い替えることもできます。
ただしその場合...

Refinement#import_methods(*modules) -> self (107.0)

モジュールからメソッドをインポートします。

...モジュールからメソッドをインポートします。

Module#includeと違って、import_methods はメソッドをコピーして
refinement に追加して、refinementでインポートしたメソッドを有効化します。

メソッドをコピーするため、Rubyコードで...
...定義されたメソッドだけしか
インポートできないことに注意してください。

//emlist[][ruby]{
module S
trUtils
def indent(level)
' ' * level + self
end
end

module M
refine String do
import_methods StrUtils
end
end

using M
p "foo".indent(3) # => " foo"...

絞り込み条件を変える

NEWS for Ruby 3.0.0 (42.0)

NEWS for Ruby 3.0.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。

...ntext. 16786
* Module
* Module#include and Module#prepend now affect classes and modules that have already included or prepended the receiver, mirroring the behavior if the arguments were included in the receiver before the other modules and classes included or prepended the receiver. 9573...
...* Module#alias_method now returns the defined alias as a symbol. 17314

//emlist[][ruby]{
class C; end
module M1; end
module M2; end
C.include M1
M1.include M2
p C.ancestors #=> [C, M1, M2, Object, Kernel, BasicObject]
//}

* Mutex
* `Mutex` is now acquired per-`Fiber` instead of per-`Thr...
...iately. This feature is designed by referring to Python's buffer protocol. 13767 14722
* Ractor related C APIs are introduced (experimental) in "include/ruby/ractor.h".

== Implementation improvements

* New method cache mechanism for Ractor. 16614
* Inline method caches pointed from ISeq ca...

Module#append_features(module_or_class) -> self (30.0)

モジュール(あるいはクラス)に self の機能を追加します。

...加します。

このメソッドは Module#include の実体であり、
include
を Ruby で書くと以下のように定義できます。

//emlist[例][ruby]{
def include(*modules)
modules
.reverse_each do |mod|
# append_features や included はプライベートメソッドなので...
...# 直接 mod.append_features(self) などとは書けない
mod.__send__(:append_features, self)
mod.__send__(:included, self)
end
end
//}

@see Module#included...

Module#const_source_location(name, inherited = true) -> [String, Integer] (24.0)

name で指定した定数の定義を含むソースコードのファイル名と行番号を配列で返します。

...します。

@param name Symbol,String で定数の名前を指定します。
@param inherited true を指定するとスーパークラスや include したモジュールで定義された定数が対象にはなります。false を指定した場合 対象にはなりません。
@return ソ...
...//emlist[例][ruby]{
# test.rb:
class A # line 1
C1 = 1
C2 = 2
end

module M # line 6
C3 = 3
end

class B < A # line 10
include
M
C4 = 4
end

class A # 継続して A を定義する
C2 = 8 # 定数を再定義する
end

p B.const_source_location('C4') # =>...
...-- Object を継承している為
p M.const_source_location('A') # => ["test.rb", 1] -- Object は継承していないが追加で modules をチェックする

p Object.const_source_location('A::C1') # => ["test.rb", 2] -- ネストの指定もサポートしている
p Object.c...

Module#ancestors -> [Class, Module] (18.0)

クラス、モジュールのスーパークラスとインクルードしているモジュール を優先順位順に配列に格納して返します。

...先順位順に配列に格納して返します。

//emlist[例][ruby]{
module Foo
end
class Bar
include
Foo
end
class Baz < Bar
p ancestors
p included_modules
p superclass
end
# => [Baz, Bar, Foo, Object, Kernel, BasicObject]
# => [Foo, Kernel]
# => Bar
//}

@see Module#included_modules...