我可以以某种方式使用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
答案 0 :(得分:2)
您的问题包含答案-使用Struct
:
RecipientScorer::ScoreResult = Struct.new(
:id,
:score_data,
:total_score,
:percent_match
)