Top > Ruby [2.2.2] > < , == , <=>


String# < , == , <=>

p "a" < "b"      # true
p "b" < "b"      # false
p "b" <= "b"     # true

p "a" == "b"     # false
p "b" == "b"     # true

p "a" <=> "b"    # -1    ←左が大きい時
p "a" <=> "a"    # 0     ←同じ時
p "c" <=> "b"    # 1     ←右が大きい時

p "azz" < "aaz"  # false
p "zaa" < "zba"  # true

<=>がいいです。



Copyright © 2015 AchaPorutePiipo All Rights Reserved.