るりまサーチ

最速Rubyリファレンスマニュアル検索!
708件ヒット [201-300件を表示] (0.098秒)

別のキーワード

  1. argf.class each
  2. argf.class each_line
  3. argf.class lines
  4. class new
  5. argf.class gets

検索結果

<< < 1 2 3 4 5 ... > >>

Module#ancestors -> [Class, Module] (115.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...

Module#included(class_or_module) -> () (115.0)

self が Module#include されたときに対象のクラスまたはモジュー ルを引数にしてインタプリタがこのメソッドを呼び出します。

...self が Module#include されたときに対象のクラスまたはモジュー
ルを引数にしてインタプリタがこのメソッドを呼び出します。

@param class_or_module Module#include を実行したオブジェクト

//emlist[例][ruby]{
module
Foo
def self.included(mod)...
...p "#{mod} include #{self}"
end
end
class
Bar
include Foo
end
# => "Bar include Foo"
//}

@see Module#append_features...

Module#prepended(class_or_module) -> () (109.0)

self が Module#prepend されたときに対象のクラスまたはモジュールを 引数にしてインタプリタがこのメソッドを呼び出します。

...self が Module#prepend されたときに対象のクラスまたはモジュールを
引数にしてインタプリタがこのメソッドを呼び出します。

@param class_or_module Module#prepend を実行したオブジェクト

//emlist[例][ruby]{
module
A
def self.prepended(mod)...
...puts "#{self} prepended to #{mod}"
end
end
module
Enumerable
prepend A
end
# => "A prepended to Enumerable"
//}

@see Module#included, Module#prepend, Module#prepend_features...

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

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

...ラス)に self の機能を追加します。

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

//emlist[例][ruby]{
def include(*modules)
module
s.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#autoload(const_name, feature) -> nil (50.0)

定数 const_name を最初に参照した時に feature を Kernel.#require するように設定します。

...と同様な方法で autoload する対象を指定する。

//emlist[例][ruby]{
# ------- /tmp/foo.rb ---------
class
Foo
class
Bar
end
end
# ----- end of /tmp/foo.rb ----

class
Foo
autoload :Bar, '/tmp/foo'
end
p Foo::Bar #=> Foo::Bar
//}

以下のようにモジュールを明示的に...
...シーバとして呼び出すこともできます。

//emlist[例][ruby]{
# ------- /tmp/foo.rb ---------
class Foo
class
Bar
end
end
# ----- end of /tmp/foo.rb ----

class
Foo
end
Foo.autoload :Bar, '/tmp/foo'
p Foo::Bar #=> Foo::Bar
//}

以下のように、autoload したライブラリ...
...た定数を定義しない場
合、NameError が発生します。

//emlist[例][ruby]{
# ------- /tmp/bar.rb ---------
class
Bar
end
# ----- end of /tmp/bar.rb ----

class
Foo
autoload :Bar, '/tmp/bar.rb'
end
p Foo::Bar
#=> -:4:in `<main>': uninitialized constant Foo::Bar (NameError)
//}

@see...

絞り込み条件を変える

Module#<(other) -> bool | nil (26.0)

比較演算子。self が other の子孫である場合、 true を返します。 self が other の先祖か同一のクラス/モジュールである場合、false を返します。

...list[例][ruby]{
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 (TypeError)
//...

Module#constants(inherit = true) -> [Symbol] (26.0)

そのモジュール(またはクラス)で定義されている定数名の配列を返します。

...@see Module.constants, Kernel.#local_variables, Kernel.#global_variables, Object#instance_variables, Module#class_variables

//emlist[Module.constants と Module#constants の違い][ruby]{
# 出力の簡略化のため起動時の定数一覧を取得して後で差し引く
$clist = Module.const...
...ants

class Foo
FOO = 1
end
class
Bar
BAR = 1

# Bar は BAR を含む
p constants # => [:BAR]
# 出力に FOO は含まれない
p Module.constants - $clist # => [:BAR, :Bar, :Foo]
class
Baz
# Baz は定数を含まない
p constants...
...]

# ネストしたクラスでは、外側のクラスで定義した定数は
# 参照可能なので、BAR は、Module.constants には含まれる
# (クラス Baz も Bar の定数なので同様)
p Module.constants - $clist # => [:BAR, :Baz, :Foo, :Bar]
end
end
//}...

Module#inspect -> String (26.0)

モジュールやクラスの名前を文字列で返します。

...t[例][ruby]{
module
A
module
B
end

p B.name #=> "A::B"

class
C
end
end

p A.name #=> "A"
p A::B.name #=> "A::B"
p A::C.name #=> "A::C"

# 名前のないモジュール / クラス
p Module.new.name #=> nil
p Class.new.name #=> nil
p Module.new.to_s #=> "#<Module:0x00007f90b0...
...9112c8>"
p Class.new.to_s #=> "#<Class:0x00007fa5c40b41b0>"
//}...

Module#name -> String | nil (26.0)

モジュールやクラスの名前を文字列で返します。

...t[例][ruby]{
module
A
module
B
end

p B.name #=> "A::B"

class
C
end
end

p A.name #=> "A"
p A::B.name #=> "A::B"
p A::C.name #=> "A::C"

# 名前のないモジュール / クラス
p Module.new.name #=> nil
p Class.new.name #=> nil
p Module.new.to_s #=> "#<Module:0x00007f90b0...
...9112c8>"
p Class.new.to_s #=> "#<Class:0x00007fa5c40b41b0>"
//}...
<< < 1 2 3 4 5 ... > >>