-1

Can I somehow use Struct or OpenStruct to make my class more concise?

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
Kamilski81
  • 14,409
  • 33
  • 108
  • 161
  • Did you try `RecipientScorer::ScoreResult = Struct.new(:id, :score_data, :total_score, :percent_match)`? – spickermann Aug 23 '18 at 15:12
  • Or https://stackoverflow.com/questions/12763016/how-to-cleanly-initialize-attributes-in-ruby-with-new – iGian Aug 23 '18 at 15:35

1 Answers1

2

Your question contains the answer - use Struct:

RecipientScorer::ScoreResult = Struct.new(
  :id,
  :score_data,
  :total_score,
  :percent_match
)
Andrey Deineko
  • 51,333
  • 10
  • 112
  • 145