📜  红宝石 |结构成员()函数

📅  最后修改于: 2022-05-13 01:55:21.415000             🧑  作者: Mango

红宝石 |结构成员()函数

members()是 Ruby 中的一个内置方法,它返回一个包含结构成员的符号数组。

示例 1

# Ruby program for members method in struct 
    
# Include struct
Student = Struct.new(:name, :address, :dept , :project)
  
#initialize values
detail = Student.new("Vishwa", "Hyderabad", "CSE" , "IOT")
  
# members used
puts detail.members  

输出

name
address
dept
project

示例 2

# Ruby program for members method in struct 
    
# Include struct
Movie = Struct.new(:name, :imdbrating)
  
# initialize values
detail = Movie.new("3idiots", 5)
  
# members used
puts detail.members  

输出

name
imdbrating