るりまサーチ

最速Rubyリファレンスマニュアル検索!
465件ヒット [1-100件を表示] (0.080秒)

別のキーワード

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

検索結果

<< 1 2 3 ... > >>

Module#include(*mod) -> self (18186.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, Ker...

TracePoint#defined_class -> Class | module (6263.0)

メソッドを定義したクラスかモジュールを返します。

...ュールを返します。

//emlist[例][ruby]{
class
C; def foo; end; end
trace = TracePoint.new(:call) do |tp|
p tp.defined_class # => C
end.enable do
C.new.foo
end
//}

メソッドがモジュールで定義されていた場合も(include に関係なく)モジュー
ルを返します。...
...//emlist[例][ruby]{
module M; def foo; end; end
class
C; include M; end;
trace = TracePoint.new(:call) do |tp|
p tp.defined_class # => M
end.enable do
C.new.foo
end
//}

[注意] 特異メソッドを実行した場合は TracePoint#defined_class は特異クラ
スを返します。また、K...
...ラメータは特異クラスではなく元のクラスを返します。

//emlist[例][ruby]{
class
C; def self.foo; end; end
trace = TracePoint.new(:call) do |tp|
p tp.defined_class # => #<Class:C>
end.enable do
C.foo
end
//}

Kernel.#set_trace_func と TracePoint の上記の差分に注...

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

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

...f が 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#include?(mod) -> bool (6132.0)

self かその親クラス / 親モジュールがモジュール mod を インクルードしていれば true を返します。

...クラス / 親モジュールがモジュール mod を
インクルードしていれば true を返します。

@param mod Module を指定します。

//emlist[例][ruby]{
module M
end
class
C1
include
M
end
class
C2 < C1
end

p C1.include?(M) # => true
p C2.include?(M) # => true
//}...

Object#respond_to?(name, include_all = false) -> bool (144.0)

オブジェクトがメソッド name を持つとき真を返します。

...

@param include_all private メソッドと protected メソッドを確認の対象に
含めるかを true か false で指定します。省略した場合
は false(含めない) を指定した事になります。

//emlist[][ruby]{
class
F
def hello...
..."Bonjour"
end
end

class
D
private
def hello
"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...
...aise NotImplementedError.new
end

def finish
puts "finish"
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.ne...

絞り込み条件を変える

Object#methods(include_inherited = true) -> [Symbol] (126.0)

そのオブジェクトに対して呼び出せるメソッド名の一覧を返します。 このメソッドは public メソッドおよび protected メソッドの名前を返します。

...す。


@param include_inherited 引数が偽の時は Object#singleton_methods(false) と同じになります。

//emlist[例1][ruby]{
class
Parent
private; def private_parent() end
protected; def protected_parent() end
public; def public_parent() end
end

class
Foo < Parent
pr...
...ivate; def private_foo() end
protected; def protected_foo() end
public; def public_foo() end
end

obj = Foo.new
class
<<obj
private; def private_singleton() end
protected; def protected_singleton() end
public; def public_singleton() end
end

# あるオブジェ...

Module#ancestors -> [Class, Module] (120.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#append_features(module_or_class) -> self (120.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...

Object#respond_to_missing?(symbol, include_private) -> bool (120.0)

自身が symbol で表されるメソッドに対し BasicObject#method_missing で反応するつもりならば真を返します。

...るべきです。

false を返します。

@param symbol メソッド名シンボル
@param include_private private method も含めたい場合に true が渡されます

//emlist[例][ruby]{
class
Sample
def method_missing(name, *args)
if name =~ /^to_*/
[name, *args] # => [:to_sam...
...ple, "sample args1", "sample args2"]
return
else
super
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)...
<< 1 2 3 ... > >>