📜  红宝石 |结构检查()函数

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

红宝石 |结构检查()函数

inspect()是 Ruby 中的一个内置方法,它返回一个带有特定结构值的字符串。

示例 1

# Ruby program for inspect method in struct 
    
# Include struct
animals = Struct.new(:name, :speciality , :found_in)
  
# initialize values
detail = animals.new("labrador", "bark" , "Newfoundland")
  
# inspect used
puts detail.inspect 

输出

struct name="labrador", speciality="bark", found_in="Newfoundland"

示例 2

# Ruby program for inspect method in struct 
    
# Include struct
animals = Struct.new(:name)
  
# initialize values
detail = animals.new("golden retriever")
  
# inspect used
puts detail.inspect

输出

struct name="golden retriever"