instance method String#<=>

self <=> other -> -1 | 0 | 1 | nil[permalink][rdoc][edit]

self と other を ASCII コード順で比較して、 self が大きい時には 1、等しい時には 0、小さい時には -1 を返します。このメソッドは Comparable モジュールのメソッドを実装するために使われます。

other が文字列でない場合、 other.to_str と other.<=> が定義されていれば 0 - (other <=> self) の結果を返します。そうでなければ nil を返します。

[PARAM] other:
文字列
[RETURN]
比較結果の整数か nil


p "aaa" <=> "xxx"   # => -1
p "aaa" <=> "aaa"   # => 0
p "xxx" <=> "aaa"   # => 1

p "string" <=> "stringAA"  # => -1
p "string" <=> "string"    # => 0
p "stringAA" <=> "string"  # => 1