logo
  • 教程列表
  • SO官方文档
  • 结构
    • 为数据创建新结构
    • 自定义结构类
    • 属性查找
  1. StackOverflow 文档
  2. Ruby Language 教程
  3. 结构
  4. 自定义结构类

自定义结构类

Created: November-22, 2018

Person = Struct.new :name do
  def greet(someone)
    "Hello #{someone}! I am #{name}!"
  end
end

Person.new('Alice').greet 'Bob'
# => "Hello Bob! I am Alice!"
  • 属性查找
  • 为数据创建新结构

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 关于我们
  • 免责声明