红宝石 |向量零?()函数
zero?()是 Ruby 中的一个内置方法,如果向量的所有元素都等于零,则返回布尔值 true,否则返回 false
Syntax: vec1.zero?()
Parameters: The function accepts no parameter
Return Value: It returns boolean value true if all elements of vector are equals to zero otherwise false
示例 1 :
# Ruby program for zero?() method in Vector
# Include matrix
require "matrix"
# Initialize the vector
vec1 = Vector[0, 0, 0]
# Prints boolean value
puts vec1.zero?()
输出:
true
示例 2 :
# Ruby program for zero?() method in Vector
# Include matrix
require "matrix"
# Initialize the vector
vec1 = Vector[0, 1, 3]
# Prints boolean value
puts vec1.zero?()
输出:
false