Array#() :() es un método de clase Array que realiza la comparación entre las dos arrays.
Sintaxis: Array.()
Parámetro: Array para la comparación
Devuelve: 1 : si a > b
-1 : si a < b
0 : si a = b
Ejemplo 1 :
# Ruby code for <=>() method # checking equality # declaring arrays a = [18, 22, 33, 4, 5, 6] # declaring arrays b = [18, 22, 33, 4, 5, 6] # declaring arrays c = [18, 22, 33, 40, 50, 6] # <=> method puts "<=> method : #{a <=> b}\n\n" # <=> method puts "<=> method : #{a <=> c}\n\n" # <=> method puts "<=> method : #{b <=> c}\n\n"
Producción :
method : 0 method : -1 method : -1
Ejemplo #2:
# Ruby code for <=>() method # checking equality # declaring arrays a = ["abc", "xyz", "dog"] # declaring arrays b = ["cat", "cat", "dog"] # declaring arrays c = ["cat", "cat", "dog"] # <=> method puts "<=> method : #{a <=> b}\n\n" # <=> method puts "<=> method : #{a <=> c}\n\n" # <=> method puts "<=> method : #{b <=> c}\n\n"
Producción :
method : -1 method : -1 method : 0
Publicación traducida automáticamente
Artículo escrito por mayank5326 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA