るりまサーチ

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

別のキーワード

  1. _builtin new
  2. _builtin inspect
  3. _builtin []
  4. _builtin to_s
  5. _builtin each

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 3 ... > >>

Object#initialize(*args, &block) -> object (26174.0)

ユーザ定義クラスのオブジェクト初期化メソッド。

...このメソッドは Class#new から新しく生成されたオブ
ジェクトの初期化のために呼び出されます。他の言語のコンストラクタに相当します。
デフォルトの動作ではなにもしません。

initialize
には
Class#new に与えられた引数が...
...

initialize
という名前のメソッドは自動的に private に設定され
ます。

@param args 初期化時の引数です。
@param block 初期化時のブロック引数です。必須ではありません。

//emlist[][ruby]{
class Foo
def initialize name
puts "initialize Fo...
...o"
@name = name
end
end

class Bar < Foo
def initialize name, pass
puts "initialize Bar"
super name
@pass = pass
end
end

it = Bar.new('myname','0500')
p it
#=> initialize Bar
# initialize Foo
# #<Bar:0x2b68f08 @name="myname", @pass="0500">
//}

@see Class#new...

Class#new(*args, &block) -> object (26154.0)

自身のインスタンスを生成して返します。 このメソッドの引数はブロック引数も含め Object#initialize に渡されます。

...ク引数も含め Object#initialize に渡されます。

new
は Class#allocate でインスタンスを生成し、
Object#initialize で初期化を行います。

@param args Object#initialize に渡される引数を指定します。

@param block Object#initialize に渡されるブロッ...
...クを指定します。

//emlist[例][ruby]{
# Class クラスのインスタンス、C クラスを生成
C = Class.new # => C

# Class クラスのインスタンス、C クラスのインスタンスを生成
C.new # => #<C:0x00005623f8b4e458>
//}...

Object#initialize_copy(obj) -> object (14156.0)

(拡張ライブラリによる) ユーザ定義クラスのオブジェクトコピーの初期化メソッド。

...し、self のインスタンス変数や特異メソッドは変化しません。
Object#clone, Object#dupの内部で使われています。

initialize
_copy は、Ruby インタプリタが知り得ない情報をコピーするた
めに使用(定義)されます。例えば C 言語でクラ...
...clone
を再定義する必要がなくなります。

デフォルトの Object#initialize_copy は、 freeze チェックおよび型のチェックを行い self
を返すだけのメソッドです。

initialize
_copy という名前のメソッドは
自動的に private に設定されます...
...利用しているかを示します。

obj.dup は、新たに生成したオブジェクトに対して
initialize
_copy を呼び

//emlist[][ruby]{
obj2 = obj.class.allocate
obj2.initialize_copy(obj)
//}

obj2 に対してさらに obj の汚染状態、インスタンス変数、ファイナラ...
...利用しているかを示します。

obj.dup は、新たに生成したオブジェクトに対して
initialize
_copy を呼び

//emlist[][ruby]{
obj2 = obj.class.allocate
obj2.initialize_copy(obj)
//}

obj2 に対してさらに obj のインスタンス変数、ファイナライザを
...

Enumerable#max {|a, b| ... } -> object | nil (8061.0)

ブロックの評価結果で各要素の大小判定を行い、最大の要素、もしくは最大の n 要素が入った降順の配列を返します。 引数を指定しない形式では要素が存在しなければ nil を返します。 引数を指定する形式では、空の配列を返します。

...:age

def initialize(name, age)
@name = name
@age = age
end
end

people = [
Person.new("sato", 55),
Person.new("sato", 33),
Person.new("sato", 11),
Person.new("suzuki", 55),
Person.new("suzuki", 33),
Person.new("suzuki", 11),
Person.new("tanaka", 55),
Person.new("tanaka",...
...33),
Person.new("tanaka", 11)
]

# 年齢が最大、名前が最小
people.max { |x, y| (x.age <=> y.age).nonzero? || y.name <=> x.name }
# => #<Person:0x007fc54b0240a0 @name="sato", @age=55>
people.max(2) { |x, y| (x.age <=> y.age).nonzero? || y.name <=> x.name }
# => [#<Person:0x007fc54b0240a0...

Enumerable#max(n) {|a, b| ... } -> Array (8061.0)

ブロックの評価結果で各要素の大小判定を行い、最大の要素、もしくは最大の n 要素が入った降順の配列を返します。 引数を指定しない形式では要素が存在しなければ nil を返します。 引数を指定する形式では、空の配列を返します。

...:age

def initialize(name, age)
@name = name
@age = age
end
end

people = [
Person.new("sato", 55),
Person.new("sato", 33),
Person.new("sato", 11),
Person.new("suzuki", 55),
Person.new("suzuki", 33),
Person.new("suzuki", 11),
Person.new("tanaka", 55),
Person.new("tanaka",...
...33),
Person.new("tanaka", 11)
]

# 年齢が最大、名前が最小
people.max { |x, y| (x.age <=> y.age).nonzero? || y.name <=> x.name }
# => #<Person:0x007fc54b0240a0 @name="sato", @age=55>
people.max(2) { |x, y| (x.age <=> y.age).nonzero? || y.name <=> x.name }
# => [#<Person:0x007fc54b0240a0...

絞り込み条件を変える

Enumerable#min {|a, b| ... } -> object | nil (8061.0)

ブロックの評価結果で各要素の大小判定を行い、最小の要素、もしくは最小の n 要素が昇順で入った配列を返します。 引数を指定しない形式では要素が存在しなければ nil を返します。 引数を指定する形式では、空の配列を返します。

...:age

def initialize(name, age)
@name = name
@age = age
end
end

people = [
Person.new("sato", 55),
Person.new("sato", 33),
Person.new("sato", 11),
Person.new("suzuki", 55),
Person.new("suzuki", 33),
Person.new("suzuki", 11),
Person.new("tanaka", 55),
Person.new("tanaka",...
...33),
Person.new("tanaka", 11)
]

# 年齢が最小、名前が最大
people.min { |x, y| (x.age <=> y.age).nonzero? || y.name <=> x.name }
# => #<Person:0x007fd6f0824190 @name="tanaka", @age=11>

people.min(2) { |x, y| (x.age <=> y.age).nonzero? || y.name <=> x.name }
# => [#<Person:0x007fb5899ef...

Enumerable#min(n) {|a, b| ... } -> Array (8061.0)

ブロックの評価結果で各要素の大小判定を行い、最小の要素、もしくは最小の n 要素が昇順で入った配列を返します。 引数を指定しない形式では要素が存在しなければ nil を返します。 引数を指定する形式では、空の配列を返します。

...:age

def initialize(name, age)
@name = name
@age = age
end
end

people = [
Person.new("sato", 55),
Person.new("sato", 33),
Person.new("sato", 11),
Person.new("suzuki", 55),
Person.new("suzuki", 33),
Person.new("suzuki", 11),
Person.new("tanaka", 55),
Person.new("tanaka",...
...33),
Person.new("tanaka", 11)
]

# 年齢が最小、名前が最大
people.min { |x, y| (x.age <=> y.age).nonzero? || y.name <=> x.name }
# => #<Person:0x007fd6f0824190 @name="tanaka", @age=11>

people.min(2) { |x, y| (x.age <=> y.age).nonzero? || y.name <=> x.name }
# => [#<Person:0x007fb5899ef...

Object#inspect -> String (8025.0)

オブジェクトを人間が読める形式に変換した文字列を返します。

...e\"]"
Time.new.inspect # => "2008-03-08 19:43:39 +0900"
//}

inspect メソッドをオーバーライドしなかった場合、クラス名とインスタンス
変数の名前、値の組を元にした文字列を返します。

//emlist[][ruby]{
class Foo
end
Foo.new.inspect...
...# => "#<Foo:0x0300c868>"

class Bar
def initialize
@bar = 1
end
end
Bar.new.inspect # => "#<Bar:0x0300c868 @bar=1>"
//}

@see Kernel.#p...

Thread::Backtrace::Location#base_label -> String (8025.0)

self が表すフレームの基本ラベルを返します。通常、 Thread::Backtrace::Location#label から修飾を取り除いたもので構成 されます。

...されます。

//emlist[例][ruby]{
# foo.rb
class Foo
attr_accessor :locations
def initialize(skip)
@locations = caller_locations(skip)
end
end

Foo.new(0..2).locations.map do |call|
puts call.base_label
end

# => initialize
# new
# <main>
//}

@see Thread::Backtrace::Location#label...

Thread::Backtrace::Location#inspect -> String (8025.0)

Thread::Backtrace::Location#to_s の結果を人間が読みやすいような文 字列に変換したオブジェクトを返します。

...][ruby]{
# foo.rb
class Foo
attr_accessor :locations
def initialize(skip)
@locations = caller_locations(skip)
end
end

Foo.new(0..2).locations.map do |call|
puts call.inspect
end

# => "path/to/foo.rb:5:in `initialize'"
# "path/to/foo.rb:9:in `new'"
# "path/to/foo.rb:9:in `<main>'"
//}...

絞り込み条件を変える

<< 1 2 3 ... > >>