I use classes for parameter serialization. Is it possible to automatically generate an constructor that accepts all instance variables as arguments?
property username : String
property password : String
# do I have to write this for every class?
def initialize(@username, @password)
Could you not put the contructor in a module and include the module?
Or use a macro to generate the constructor?
Thanks. This is what I was looking for.
There is a built in helper for this
username : String,
password : String
params = RequestParameters.new("user", "pass")
Very little documentation on it, but I use it all the time
# you can also define defaults
username : String = "admin",
password : String = "password"
Worth pointing out that the main catch with using
record is it creates a
struct, so the resulting object would lack any setters and would be passed by value. I.e. great option for representing a request body/response, but not as great if you want to pass it around while mutating it.