るりまサーチ

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

別のキーワード

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

クラス

モジュール

キーワード

検索結果

<< 1 2 3 ... > >>

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

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

...t[例][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)
//}...

Class#subclasses -> [Class] (15252.0)

自身が直接のスーパークラスになっている(特異クラスを除く)クラスの配列を返します。 返り値の配列の順序は未定義です。

...を除く)クラスの配列を返します。
返り値の配列の順序は未定義です。

//emlist[例][ruby]{
class
A; end
class
B < A; end
class
C < B; end
class
D < A; end

A.subclasses # => [D, B]
B.subclasses # => [C]
C.subclasses # => []
//}

@see Class#superclass...

Class#superclass -> Class | nil (15228.0)

自身のスーパークラスを返します。

...{
File.superclass #=> IO
IO.superclass #=> Object
class
Foo; end
class
Bar < Foo; end
Bar.superclass #=> Foo
Object.superclass #=> BasicObject
//}

ただし BasicObject.superclass は nil を返します。

//emlist[例][ruby]{
BasicObject.superclass #=> nil...
...//}

@see Class#subclasses...

Class#inherited(subclass) -> () (9145.0)

クラスのサブクラスが定義された時、新しく生成されたサブクラスを引数 にインタプリタから呼び出されます。このメソッドが呼ばれるタイミングは クラス定義文の実行直前です。

...@param subclass プログラム内で新たに定義された自身のサブクラスです。

//emlist[例][ruby]{
class
Foo
def Foo.inherited(subclass)
puts "class \"#{self}\" was inherited by \"#{subclass}\""
end
end
class
Bar < Foo
puts "executing class body"
end

# => class "Foo" was...
...inherited by "Bar"
# executing class body
//}...

Module#class_variables(inherit = true) -> [Symbol] (6140.0)

クラス/モジュールに定義されているクラス変数の名前の配列を返します。

...ュールのクラス変数を含みます。

//emlist[例][ruby]{
class
One
@@var1 = 1
end
class
Two < One
@@var2 = 2
end
One.class_variables # => [:@@var1]
Two.class_variables # => [:@@var2, :@@var1]
Two.class_variables(false) # => [:@@var2]
//}

@see Module.constants, Ker...

絞り込み条件を変える

Module#<=>(other) -> Integer | nil (6127.0)

self と other の継承関係を比較します。

...のクラスやモジュール

//emlist[例][ruby]{
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
//}...

Method#<<(callable) -> Proc (6109.0)

self と引数を合成した Proc を返します。

...thod(:f) << method(:g)).call(3) # => 36
//}

//emlist[call を定義したオブジェクトを渡す例][ruby]{
class
WordScanner
def self.call(str)
str.scan(/\w+/)
end
end

File.write('testfile', <<~TEXT)
Hello, World!
Hello, Ruby!
TEXT

pipeline = method(:pp) << WordScanner << File.me...
...thod(:read)
pipeline.call('testfile') # => ["Hello", "World", "Hello", "Ruby"]
//}

@see Proc#<<, Proc#>>...

Proc#<<(callable) -> Proc (6109.0)

self と引数を合成した Proc を返します。

...(f << g).call(3) # => 36
//}

//emlist[call を定義したオブジェクトを渡す例][ruby]{
class
WordScanner
def self.call(str)
str.scan(/\w+/)
end
end

File.write('testfile', <<~TEXT)
Hello, World!
Hello, Ruby!
TEXT

pipeline = proc { |data| puts "word count: #{data.size}" } << W...
...ordScanner << File.method(:read)
pipeline.call('testfile') # => word count: 4
//}

@see Method#<<, Method#>>...

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

Method#inspect -> String (39.0)

self を読みやすい文字列として返します。

...self を読みやすい文字列として返します。

以下の形式の文字列を返します。

#<Method: klass1(klass2)#method> (形式1)

klass1 は、Method#inspect では、レシーバのクラス名、
UnboundMethod#inspect では、UnboundMethod オブジェクト...
...o
def foo
"foo"
end
end
class
Bar
include Foo
def bar
end
end

p Bar.new.method(:foo) # => #<Method: Bar(Foo)#foo>
p Bar.new.method(:bar) # => #<Method: Bar#bar>
//}

klass1 と klass2 が同じ場合は以下の形式になります。
#<Method: klass1#method>...
...(形式2)

特異メソッドに対しては、
#<Method: obj.method> (形式3)
#<Method: klass1(klass2).method> (形式4)
という形式の文字列を返します。二番目の形式では klass1 はレシーバ、
klass2 は実際に...
...self を読みやすい文字列として返します。

以下の形式の文字列を返します。

#<Method: klass1(klass2)#method(arg) foo.rb:2> (形式1)

klass1 は、Method#inspect では、レシーバのクラス名、
UnboundMethod#inspect では、UnboundMethod オブジェクト...
...foo"
end
end
class
Bar
include Foo
def bar(a, b)
end
end

p Bar.new.method(:foo) # => #<Method: Bar(Foo)#foo() test.rb:2>
p Bar.new.method(:bar) # => #<Method: Bar#bar(a, b) test.rb:8>
//}

klass1 と klass2 が同じ場合は以下の形式になります。
#<Method: klass1...
...#method() foo.rb:2> (形式2)

特異メソッドに対しては、
#<Method: obj.method() foo.rb:2> (形式3)
#<Method: klass1(klass2).method() foo.rb:2> (形式4)
という形式の文字列を返します。二番目の形式では klass1 はレシーバ、
klas...

絞り込み条件を変える

Method#to_s -> String (39.0)

self を読みやすい文字列として返します。

...self を読みやすい文字列として返します。

以下の形式の文字列を返します。

#<Method: klass1(klass2)#method> (形式1)

klass1 は、Method#inspect では、レシーバのクラス名、
UnboundMethod#inspect では、UnboundMethod オブジェクト...
...o
def foo
"foo"
end
end
class
Bar
include Foo
def bar
end
end

p Bar.new.method(:foo) # => #<Method: Bar(Foo)#foo>
p Bar.new.method(:bar) # => #<Method: Bar#bar>
//}

klass1 と klass2 が同じ場合は以下の形式になります。
#<Method: klass1#method>...
...(形式2)

特異メソッドに対しては、
#<Method: obj.method> (形式3)
#<Method: klass1(klass2).method> (形式4)
という形式の文字列を返します。二番目の形式では klass1 はレシーバ、
klass2 は実際に...
...self を読みやすい文字列として返します。

以下の形式の文字列を返します。

#<Method: klass1(klass2)#method(arg) foo.rb:2> (形式1)

klass1 は、Method#inspect では、レシーバのクラス名、
UnboundMethod#inspect では、UnboundMethod オブジェクト...
...foo"
end
end
class
Bar
include Foo
def bar(a, b)
end
end

p Bar.new.method(:foo) # => #<Method: Bar(Foo)#foo() test.rb:2>
p Bar.new.method(:bar) # => #<Method: Bar#bar(a, b) test.rb:8>
//}

klass1 と klass2 が同じ場合は以下の形式になります。
#<Method: klass1...
...#method() foo.rb:2> (形式2)

特異メソッドに対しては、
#<Method: obj.method() foo.rb:2> (形式3)
#<Method: klass1(klass2).method() foo.rb:2> (形式4)
という形式の文字列を返します。二番目の形式では klass1 はレシーバ、
klas...
<< 1 2 3 ... > >>