红宝石 |数字 dup()函数
dup()是 Ruby 中的一个内置方法,它返回数字本身。
Syntax: num1.dup()
Parameters: The function needs a number.
Return Value: It returns itself only.
示例 1 :
Ruby
# Ruby program for dup() method in Numeric
# Initialize a number
num1 = 1.7
# Function used
num = num1.dup()
# Prints dup() of num
puts num
Ruby
# Ruby program for dup() method in Numeric
# Initialize a number
num1 = 19
# Function used
num = num1.dup()
# Prints dup() of num
puts num
输出:
1.7
示例 2 :
红宝石
# Ruby program for dup() method in Numeric
# Initialize a number
num1 = 19
# Function used
num = num1.dup()
# Prints dup() of num
puts num
输出:
19