るりまサーチ

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

別のキーワード

  1. _builtin rational
  2. rational **
  3. json/add/rational to_json
  4. json/add/rational json_create

ライブラリ

クラス

検索結果

Rational#<=>(other) -> -1 | 0 | 1 | nil (27185.0)

self と other を比較して、self が大きい時に 1、等しい時に 0、小さい時に -1 を返します。比較できない場合はnilを返します。

...ます。

//emlist[例][ruby]{
Rational
(2, 3) <=> Rational(2, 3) # => 0
Rational
(5) <=> 5 # => 0
Rational
(2, 3) <=> Rational(1,3) # => 1
Rational
(1, 3) <=> 1 # => -1
Rational
(1, 3) <=> 0.3 # => 1
Rational
(1, 3) <=> nil # => nil
//}...

Date#<=>(other) -> -1 | 0 | 1 | nil (18138.0)

二つの日付を比較します。 同じ日付なら 0 を、self が other よりあとの日付なら 1 を、 その逆なら -1 を返します。

...e "date"

p Date.new(2001, 2, 3) <=> Date.new(2001, 2, 4) # => -1
p Date.new(2001, 2, 3) <=> Date.new(2001, 2, 3) # => 0
p Date.new(2001, 2, 3) <=> Date.new(2001, 2, 2) # => 1
p Date.new(2001, 2, 3) <=> Object.new # => nil
p Date.new(2001, 2, 3) <=> Rational(4903887, 2) # => 0
//}

@param...

Numeric#nonzero? -> self | nil (19.0)

自身がゼロの時 nil を返し、非ゼロの時 self を返します。

...#=> nil
p Rational(0, 2).nonzero? #=> nil
//}

非ゼロの時に self を返すため、自身が 0 の時に他の処理をさせたい場合に以
下のように記述する事もできます。

//emlist[例][ruby]{
a = %w( z Bb bB bb BB a aA Aa AA A )
b = a.sort {|a,b| (a.downcase <=> b.downc...
...ase).nonzero? || a <=> b }
b #=> ["A", "a", "AA", "Aa", "aA", "BB", "Bb", "bB", "bb", "z"]
//}

@see Numeric#zero?...