← Back to Upcase

How to create a Parameter Object

(Anthony) #1

I’m reading through Ruby Science. Currently I’m at the section on Parameter Objects. It is said that a Parameter Object is a solution to Long Parameter Lists. As an example is shown the recipient object that groups the properties first_name, last_name and email.

But nowhere is shown how the recipient object is created. Can someone show me how to create a Parameter Object?

thanks for your help,


(Andy Waite) #2

It’s normally just a simple class with an attribute for each field, e.g.:

class Recipient
  def initialize(first_name:, last_name:, email:)
    @first_name = first_name
    @last_name = last_name
    @email = email

  attr_reader :first_name, :last_name, :email

(Anthony) #3

Oh I see. Thanks Andy.