Array#one?() : one?() es un método de clase Array que verifica si la array tiene solo un elemento de array.
Sintaxis: Array.one?()
Parámetro: Array
Devuelve: verdadero: si la array tiene solo un elemento, de lo contrario, devuelve falso.
Ejemplo 1 :
# Ruby code for one?() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array b = [1, 4, 1, 1, 88, 9] # declaring array c = [2] # one? method example puts "one?() method form : #{a.one?()}\n\n" puts "one?() method form : #{b.one?()}\n\n" puts "one?() method form : #{c.one?()}\n\n"
Producción :
one?() method form : false one?() method form : false one?() method form : true
Ejemplo #2:
# Ruby code for one?() method # declaring array a = ["abc", "nil", "dog"] # declaring array c = ["cow"] # declaring array b = ["cow", nil, "dog"] # one? method example puts "one?() method form : #{a.one?()}\n\n" puts "one?() method form : #{b.one?()}\n\n" puts "one?() method form : #{c.one?()}\n\n"
Producción :
one?() method form : false one?() method form : false one?() method form : true
Publicación traducida automáticamente
Artículo escrito por mayank5326 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA