るりまサーチ

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

別のキーワード

  1. _builtin <
  2. bigdecimal <
  3. integer <
  4. float <
  5. comparable <

ライブラリ

モジュール

キーワード

検索結果

<< 1 2 > >>

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

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

...トの動作ではなにもしません。

initialize
には
Class#new に与えられた引数がそのまま渡されます。

サブクラスではこのメソッドを必要に応じて再定義されること
が期待されています。

initialize
という名前のメソッドは自動...
...y]{
class Foo
def initialize name
puts "initialize Foo"
@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 @nam...

BasicObject#! -> bool (19.0)

オブジェクトを真偽値として評価し、その論理否定を返します。

...tionRecorder < BasicObject
def initialize
@count = 0
end
attr_reader :count

def !
@count += 1
super
end
end

recorder = NegationRecorder.new
!recorder
!!!!!!!recorder
puts 'hoge' if !recorder

puts recorder.count #=> 3
//}

//emlist[例][ruby]{
class AnotherFalse < BasicObjec...

Thread::Backtrace::Location#base_label -> String (19.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...

BasicObject#!=(other) -> bool (13.0)

オブジェクトが other と等しくないことを判定します。

...@param other 比較対象となるオブジェクト
@see BasicObject#==, BasicObject#!

//emlist[例][ruby]{
class NonequalityRecorder < BasicObject
def initialize
@count = 0
end
attr_reader :count

def !=(other)
@count += 1
super
end
end
recorder = NonequalityRecorder.new

re...

BasicObject#==(other) -> bool (13.0)

オブジェクトが other と等しければ真を、さもなくば偽を返します。

...象となるオブジェクト
@return other が self と同値であれば真、さもなくば偽

//emlist[例][ruby]{
class Person < BasicObject
def initialize(name, age)
@name = name
@age = age
end
end

tanaka1 = Person.new("tanaka", 24)
tanaka2 = Person.new("tanaka", 24)

tanaka1 =...

絞り込み条件を変える

BasicObject#instance_eval {|obj| ... } -> object (13.0)

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

...ます。
スタックトレースの表示などを差し替えることができます。

//emlist[例][ruby]{
class Foo
def initialize data
@key = data
end
private
def do_fuga
p 'secret'
end
end

some = Foo.new 'XXX'
some.instance_eval{p @key} #=> "XXX"
some.insta...
...timeError)
messg = 'unknown'
some.instance_eval 'raise messg','file.rb',999 # file.rb:999: unknown (RuntimeError)
//}

//emlist[例][ruby]{
class Bar < BasicObject
def call1
instance_eval("::ENV.class")
end
def call2
instance_eval("ENV.class")
end
end

bar = Bar.new
bar.call1 # => Ob...

BasicObject#instance_eval(expr, filename = "(eval)", lineno = 1) -> object (13.0)

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

...ます。
スタックトレースの表示などを差し替えることができます。

//emlist[例][ruby]{
class Foo
def initialize data
@key = data
end
private
def do_fuga
p 'secret'
end
end

some = Foo.new 'XXX'
some.instance_eval{p @key} #=> "XXX"
some.insta...
...timeError)
messg = 'unknown'
some.instance_eval 'raise messg','file.rb',999 # file.rb:999: unknown (RuntimeError)
//}

//emlist[例][ruby]{
class Bar < BasicObject
def call1
instance_eval("::ENV.class")
end
def call2
instance_eval("ENV.class")
end
end

bar = Bar.new
bar.call1 # => Ob...

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

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

...します。
引数を指定する形式では、空の配列を返します。

ブロックの値は、a > b のとき正、
a == b のとき 0、a < b のとき負の整数を、期待しています。

該当する要素が複数存在する場合、どの要素を返すかは不定です。

@...
...peError ブロックが整数以外を返したときに発生します。

//emlist[例][ruby]{
class Person
attr_reader :name, :age

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

people = [
Person.new("sato", 55),
Person.new("sato", 33),
Person.new("sato", 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 @name="sato", @age=55>, #<Person:0x007fc54c033ea0 @name="suzu...

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

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

...します。
引数を指定する形式では、空の配列を返します。

ブロックの値は、a > b のとき正、
a == b のとき 0、a < b のとき負の整数を、期待しています。

該当する要素が複数存在する場合、どの要素を返すかは不定です。

@...
...peError ブロックが整数以外を返したときに発生します。

//emlist[例][ruby]{
class Person
attr_reader :name, :age

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

people = [
Person.new("sato", 55),
Person.new("sato", 33),
Person.new("sato", 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 @name="sato", @age=55>, #<Person:0x007fc54c033ea0 @name="suzu...
<< 1 2 > >>