红宝石 |结构值()函数
values()是 Ruby 中的一个内置方法,它返回一个包含特定结构值的数组。
Syntax: struct_name.to_a[integer]
Parameters: The function accepts an integer parameter which specifies the struct value to be returned.
Return Value: It returns the value of struct.
示例 1 :
# Ruby program for values method in struct
# Include struct
place = Struct.new(:name, :speciality)
# initialize values
detail = place.new("nagpur","orange")
# print value
puts detail.values
输出:
nagpur
orange
示例 2 :
# Ruby program for values method in struct
# Include struct
animals = Struct.new(:name, :speciality , :found_in)
# initialize values
detail = animals.new("labrador", "bark" , "Newfoundland")
# values used
puts detail.values
输出:
labrador
bark
Newfoundland