代码之家  ›  专栏  ›  技术社区  ›  Kamilski81

我怎样才能使我的简单Ruby类更简洁,看起来更麻烦?[副本]

  •  -1
  • Kamilski81  · 技术社区  · 6 年前

    我能用Struct或OpenStruct使我的类更简洁吗?

    class RecipientScorer::ScoreResult
    
      attr_accessor :id, :score_data, :total_score, :percent_match
    
      def initialize(id, score_data, total_score, percent_match)
        @id = id
        @score_data = score_data
        @total_score = total_score
        @percent_match = percent_match
      end
    
    end
    
    1 回复  |  直到 6 年前
        1
  •  2
  •   Andrey Deineko    6 年前

    你的问题包含答案-使用 Struct

    RecipientScorer::ScoreResult = Struct.new(
      :id,
      :score_data,
      :total_score,
      :percent_match
    )