Chautauqua Logo

Ruby module Comparable interactive

Prompt icon → Click to get an interactive sample (type in code)

Methods

String

# Uses spaceship <=> operator
<=>'a'<=>'b'; 'a'<=>'a'; 'b'<=>'a' # -1;0;1 Documentation Interactive samplePlayground
-1
 
<'foo' < 'foo' # false
<='foo' <= 'foo' # true
== (alias eql?)'foo' == 'foo' # true
>'foo' > 'foo' # false
>='foo' >=; 'foo' # true
between?'c'.between?('a','d') # true Documentation Interactive samplePlayground
true
clamp'd'.clamp('a'..'f'); 'z'.clamp(…); # d,f Documentation Interactive samplePlayground
f

 

Numeric

# Uses spaceship <=> operator
<=>1<=>2; 1<=>1; 2<=>1 # -1;0;1 Documentation Interactive samplePlayground
-1
 
<1 < 1 # false
<=1 <= 1 # true
== (alias eql?)1 == 1 # true
>1 > '1 # false
>=1 >=; 1 # true
between?3.between?(1,5) # true Documentation Interactive samplePlayground
true
clamp7.clamp(0,50); 70.clamp(0,50) # 7; 50 Documentation Interactive samplePlayground
7