HashStruct is similar to
Struct from Ruby standard library, the difference is that
HashStruct.generate creates a class which takes a hash with attributes rather than just positional arguments as
The point is that this is behaviour which all the model have, so you can use
HashStruct to test thinks which expect something what quacks like a model class.
User = .(:first_name, :last_name) @user = User.new(first_name: "Jakub", last_name: "Stastny")
module TestMixin def say_hi() puts("Hi!") end end .extend(TestMixin) User = .(:first_name, :last_name) User.say_hi # => "Hi!"
.send(:include, TestMixin) User = .(:first_name, :last_name) User.new.say_hi # => "Hi!"
You may want to create your custom class inhterited from
HashStruct in case you want to extend it.