るりまサーチ

最速Rubyリファレンスマニュアル検索!
1674件ヒット [101-200件を表示] (0.059秒)

別のキーワード

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

クラス

モジュール

キーワード

検索結果

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

Struct.new(*args, keyword_init: nil) {|subclass| block } -> Class (15525.0)

Struct クラスに新しいサブクラスを作って、それを返します。

...では構造体のメンバに対するアクセスメソッドが定義されています。

//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "name:%s age:%d", fred.name, fred.age
#=> "name:fred age:6" を出力します
//}

実装の都合...
...emlist[例][ruby]{
Point = Struct.new(:x, :y, keyword_init: true) # => Point(keyword_init: true)
Point.new(x: 1, y: 2) # => #<struct Point x=1, y=2>
Point.new(x: 1) # => #<struct Point x=1, y=nil>
Point.new(y: 2) # => #<struct Point x=nil, y=2>
Point.new(z: 3) # ArgumentError (unkn...
...{
Point = Struct.new(:x, :y)
Point.new(x: 1, y: 2) # => #<struct Point x={:x=>1, :y=>2}, y=nil>
# warning: Passing only keyword arguments to Struct#initialize will behave differently from Ruby 3.2. Please use a Hash literal like .new({k: v}) instead of .new(k: v).

# keywor...
...Point1 = Struct.new(:x, :y)
Point1.new(1, 2) # => #<struct Point1 x=1, y=2>
Point1.new(x: 1, y: 2) # => #<struct Point1 x=1, y=2>
Point1.new(x: 1) # => #<struct Point1 x=1, y=nil>
Point1.new(y: 2) # => #<struct Point1 x=nil, y=2>
Point1.new(x: 1, y: 2, z: 3...
...Struct.new(:x, :y, keyword_init: nil)
Point2.new(1, 2) # => #<struct Point2 x=1, y=2>
Point2.new(x: 1, y: 2) # => #<struct Point2 x=1, y=2>
Point2.new(x: 1) # => #<struct Point2 x=1, y=nil>
Point2.new(y: 2) # => #<struct Point2 x=nil, y=2>
Point2.new(x: 1,...

Struct.new(*args, keyword_init: nil) -> Class (15425.0)

Struct クラスに新しいサブクラスを作って、それを返します。

...では構造体のメンバに対するアクセスメソッドが定義されています。

//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "name:%s age:%d", fred.name, fred.age
#=> "name:fred age:6" を出力します
//}

実装の都合...
...Point1 = Struct.new(:x, :y)
Point1.new(1, 2) # => #<struct Point1 x=1, y=2>
Point1.new(x: 1, y: 2) # => #<struct Point1 x=1, y=2>
Point1.new(x: 1) # => #<struct Point1 x=1, y=nil>
Point1.new(y: 2) # => #<struct Point1 x=nil, y=2>
Point1.new(x: 1, y: 2, z: 3...
...Struct.new(:x, :y, keyword_init: nil)
Point2.new(1, 2) # => #<struct Point2 x=1, y=2>
Point2.new(x: 1, y: 2) # => #<struct Point2 x=1, y=2>
Point2.new(x: 1) # => #<struct Point2 x=1, y=nil>
Point2.new(y: 2) # => #<struct Point2 x=nil, y=2>
Point2.new(x: 1,...

Struct.new(*args) {|subclass| block } -> Class (15405.0)

Struct クラスに新しいサブクラスを作って、それを返します。

...では構造体のメンバに対するアクセスメソッドが定義されています。

//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "name:%s age:%d", fred.name, fred.age
#=> "name:fred age:6" を出力します
//}

実装の都合...
...emlist[例][ruby]{
Point = Struct.new(:x, :y, keyword_init: true) # => Point(keyword_init: true)
Point.new(x: 1, y: 2) # => #<struct Point x=1, y=2>
Point.new(x: 1) # => #<struct Point x=1, y=nil>
Point.new(y: 2) # => #<struct Point x=nil, y=2>
Point.new(z: 3) # ArgumentError (unkn...
...ラーになります。

//emlist[例][ruby]{
p Struct.new('foo', 'bar')
# => -:1:in `new': identifier foo needs to be constant (NameError)
//}

また args[1..-1] は、Symbol か String で指定します。

//emlist[例][ruby]{
p Struct.new("Foo", :foo, :bar) # => Struct::Foo
//}

=== 第一...

Struct.new(*args, keyword_init: false) {|subclass| block } -> Class (15405.0)

Struct クラスに新しいサブクラスを作って、それを返します。

...では構造体のメンバに対するアクセスメソッドが定義されています。

//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "name:%s age:%d", fred.name, fred.age
#=> "name:fred age:6" を出力します
//}

実装の都合...
...emlist[例][ruby]{
Point = Struct.new(:x, :y, keyword_init: true) # => Point(keyword_init: true)
Point.new(x: 1, y: 2) # => #<struct Point x=1, y=2>
Point.new(x: 1) # => #<struct Point x=1, y=nil>
Point.new(y: 2) # => #<struct Point x=nil, y=2>
Point.new(z: 3) # ArgumentError (unkn...
...ラーになります。

//emlist[例][ruby]{
p Struct.new('foo', 'bar')
# => -:1:in `new': identifier foo needs to be constant (NameError)
//}

また args[1..-1] は、Symbol か String で指定します。

//emlist[例][ruby]{
p Struct.new("Foo", :foo, :bar) # => Struct::Foo
//}

=== 第一...

Struct.new(*args, keyword_init: nil) -> Class (15341.0)

Struct クラスに新しいサブクラスを作って、それを返します。

...では構造体のメンバに対するアクセスメソッドが定義されています。

//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "name:%s age:%d", fred.name, fred.age
#=> "name:fred age:6" を出力します
//}

実装の都合...
...emlist[例][ruby]{
Point = Struct.new(:x, :y, keyword_init: true) # => Point(keyword_init: true)
Point.new(x: 1, y: 2) # => #<struct Point x=1, y=2>
Point.new(x: 1) # => #<struct Point x=1, y=nil>
Point.new(y: 2) # => #<struct Point x=nil, y=2>
Point.new(z: 3) # ArgumentError (unkn...
...{
Point = Struct.new(:x, :y)
Point.new(x: 1, y: 2) # => #<struct Point x={:x=>1, :y=>2}, y=nil>
# warning: Passing only keyword arguments to Struct#initialize will behave differently from Ruby 3.2. Please use a Hash literal like .new({k: v}) instead of .new(k: v).

# keywor...

絞り込み条件を変える

Struct.new(*args) -> Class (15305.0)

Struct クラスに新しいサブクラスを作って、それを返します。

...では構造体のメンバに対するアクセスメソッドが定義されています。

//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "name:%s age:%d", fred.name, fred.age
#=> "name:fred age:6" を出力します
//}

実装の都合...
...emlist[例][ruby]{
Point = Struct.new(:x, :y, keyword_init: true) # => Point(keyword_init: true)
Point.new(x: 1, y: 2) # => #<struct Point x=1, y=2>
Point.new(x: 1) # => #<struct Point x=1, y=nil>
Point.new(y: 2) # => #<struct Point x=nil, y=2>
Point.new(z: 3) # ArgumentError (unkn...
...ラーになります。

//emlist[例][ruby]{
p Struct.new('foo', 'bar')
# => -:1:in `new': identifier foo needs to be constant (NameError)
//}

また args[1..-1] は、Symbol か String で指定します。

//emlist[例][ruby]{
p Struct.new("Foo", :foo, :bar) # => Struct::Foo
//}

=== 第一...

Struct.new(*args, keyword_init: false) -> Class (15305.0)

Struct クラスに新しいサブクラスを作って、それを返します。

...では構造体のメンバに対するアクセスメソッドが定義されています。

//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "name:%s age:%d", fred.name, fred.age
#=> "name:fred age:6" を出力します
//}

実装の都合...
...emlist[例][ruby]{
Point = Struct.new(:x, :y, keyword_init: true) # => Point(keyword_init: true)
Point.new(x: 1, y: 2) # => #<struct Point x=1, y=2>
Point.new(x: 1) # => #<struct Point x=1, y=nil>
Point.new(y: 2) # => #<struct Point x=nil, y=2>
Point.new(z: 3) # ArgumentError (unkn...
...ラーになります。

//emlist[例][ruby]{
p Struct.new('foo', 'bar')
# => -:1:in `new': identifier foo needs to be constant (NameError)
//}

また args[1..-1] は、Symbol か String で指定します。

//emlist[例][ruby]{
p Struct.new("Foo", :foo, :bar) # => Struct::Foo
//}

=== 第一...

Struct.new(*args) -> Struct (15155.0)

(このメソッドは Struct の下位クラスにのみ定義されています) 構造体オブジェクトを生成して返します。

...なければ nil です。

@return 構造体クラスのインスタンス。

@raise ArgumentError 構造体のメンバの数よりも多くの引数を指定した場合に発生します。

//emlist[例][ruby]{
Foo = Struct.new(:foo, :bar)
foo = Foo.new(1)
p foo.values # => [1, nil]
//}...

IO.new(fd, mode = "r", **opts) -> IO (15139.0)

オープン済みのファイルディスクリプタ fd に対する新しい IO オブジェクトを生成して返します。

...てブロックを
実行します。ブロックの終了とともに fd はクローズされます。ブロックの結果を返します。
IO.new, IO.for_fd はブロックを受け付けません。

=== キーワード引数
このメソッドは以下のキーワード引数を利用でき...
...X IO オブジェクトの生成に失敗した場合に発生します。

//emlist[例:IO.new による読み込みモードでのファイルオープン][ruby]{
io = IO.new(IO.sysopen("testfile"))
io.class # => IO
io.close
//}

//emlist[例:IO.for_fd による読み込み・バイナリモード...
..., "\xBF\xAA\x16\x04.\b\xCB\x12\xACoeQ\xFDv2\xCF9+\x81\x18")
io = IO.for_fd(IO.sysopen("testfile"), "r", binmode: true)
io.class # => IO
io.binmode? # => true
io.close
//}

//emlist[例:IO.open によるファイルオープン][ruby]{
IO.open(IO.sysopen("testfile")) { |io| p io.class } # => IO
//}...

Struct.new(*args) -> Struct (15135.0)

(このメソッドは Struct の下位クラスにのみ定義されています) 構造体オブジェクトを生成して返します。

...なければ nil です。

@return 構造体クラスのインスタンス。

@raise ArgumentError 構造体のメンバの数よりも多くの引数を指定した場合に発生します。

//emlist[例][ruby]{
Foo = Struct.new(:foo, :bar)
foo = Foo.new(1)
p foo.values # => [1, nil]
//}...

絞り込み条件を変える

Class#allocate -> object (9014.0)

自身のインスタンスを生成して返します。生成したオブジェクトは 自身のインスタンスであること以外には何も特性を持ちません。

...したオブジェクトは
自身のインスタンスであること以外には何も特性を持ちません。

//emlist[例][ruby]{
klass = Class.new do
def initialize(*args)
@initialized = true
end

def initialized?
@initialized || false
end
end

klass.allocate.initialized? #=...

TracePoint#defined_class -> Class | module (6282.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 の上記の差分に注...

Object#singleton_class -> Class (6246.0)

レシーバの特異クラスを返します。 まだ特異クラスがなければ、新しく作成します。

...れ NilClass, TrueClass,
FalseClass を返します。

@raise TypeError レシーバが Integer、Float、Symbol の場合に発生します。

//emlist[][ruby]{
Object.new.singleton_class #=> #<Class:#<Object:0xb7ce1e24>>
String.singleton_class #=> #<Class:String>
nil.singleton_class...
...#=> NilClass
//}

@see Object#class...

Module#class_eval {|mod| ... } -> object (6134.0)

モジュールのコンテキストで文字列 expr またはモジュール自身をブロックパラメータとするブロックを 評価してその結果を返します。

...
つまり、そのモジュールの定義式の中にあるかのように実行されます。

ただし、ローカル変数は module_eval/class_eval の外側のスコープと共有します。

文字列が与えられた場合には、定数とクラス変数のスコープは自身の...
...などを差し替えることができます。

//emlist[例][ruby]{
class
C
end
a = 1
C.class_eval %Q{
def m # メソッドを動的に定義できる。
return :m, #{a}
end
}

p C.new.m #=> [:m, 1]
//}

@see BasicObject#instance_eval, Module.new, Kernel.#eval...

Module#class_eval(expr, fname = "(eval)", lineno = 1) -> object (6134.0)

モジュールのコンテキストで文字列 expr またはモジュール自身をブロックパラメータとするブロックを 評価してその結果を返します。

...
つまり、そのモジュールの定義式の中にあるかのように実行されます。

ただし、ローカル変数は module_eval/class_eval の外側のスコープと共有します。

文字列が与えられた場合には、定数とクラス変数のスコープは自身の...
...などを差し替えることができます。

//emlist[例][ruby]{
class
C
end
a = 1
C.class_eval %Q{
def m # メソッドを動的に定義できる。
return :m, #{a}
end
}

p C.new.m #=> [:m, 1]
//}

@see BasicObject#instance_eval, Module.new, Kernel.#eval...

絞り込み条件を変える

Module#class_exec(*args) {|*vars| ... } -> object (6127.0)

与えられたブロックを指定された args を引数としてモジュールのコンテキストで評価します。

...数を指定します。


//emlist[例][ruby]{
class
Thing
end
c = 1

Thing.class_exec{
def hello()
"Hello there!"
end

define_method(:foo) do # ローカル変数がブロックの外側を参照している
c
end
}

t = Thing.new
p t.hello() #=> "Hello there!"
p t.f...
...oo() #=> 1
//}

@see Module#module_eval, Module#class_eval...
<< < 1 2 3 4 ... > >>