Custom class vs. Nested hash as a parameter

I’m looking for an opinion along with maybe personal experiences on
this. I’m building a gem and currently I’ve built it to use custom
classes as parameters for initializing some of the main classes. as an

class Carrier
def initialize(shipper, recipient)

class Person
attr_reader :first_name, :last_name

def initialize(first_name, last_name)
@first_name, @last_name = first_name, last_name

shipper =“John”, “Doe”)
recipient =“Jane”, “Doe”), recipient)

or should I use a hash like this:

class Carrier
def initialize(shipper, recipient)

shipper = {first_name: “John”, last_name: “Doe”}
recipient = {first_name: “Jane”, last_name: “Doe”}, recipient)

I’ve read a few opinions on the internet about this matter, but I’m
still looking for more reasons why one way should be used over the
other. This code it pretty simple in comparison to my own, so I’ll
clarify that if I used hashes, that they would be nested up to
potentially 3 levels deep.

Another thing I wonder is from a developers standpoint, if using a gem,
would you rather have to instantiate other custom class objects for
passing into a main class or would you find it better to just need to
pass a hash?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs