positive?()是Ruby中的內置函數,如果有理數大於零,則返回布爾值true,否則返回false
用法:rat.positive?()
參數:該函數不接受任何參數
返回值:如果有理數大於零,則返回布爾值true,否則返回false
例子1:
# Ruby program for positive?() method
# Initialize rational number
rat1 = Rational(-2, 9)
# Prints the boolean value
puts rat1.positive?()
輸出:
false
例子2:
# Ruby program for positive?() method
# Initialize rational number
rat1 = Rational('1.23')
# Prints the boolean value
puts rat1.positive?()
輸出:
true
相關用法
- Ruby Rational abs()用法及代碼示例
- Ruby Rational quo()用法及代碼示例
- Ruby Rational truncate()用法及代碼示例
- Ruby Rational to_s()用法及代碼示例
- Ruby Rational to_r()用法及代碼示例
- Ruby Rational to_f()用法及代碼示例
- Ruby Rational denominator()用法及代碼示例
- Ruby Rational fdiv()用法及代碼示例
- Ruby Rational floor()用法及代碼示例
- Ruby Rational rationalize()用法及代碼示例
- Ruby Rational negative?()用法及代碼示例
- Ruby Rational round()用法及代碼示例
- Ruby Rational ceil()用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 Ruby | Rational positive?() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。