Goltergaul/definition

Provide something like dry-initializer solves

Closed this issue · 1 comments

Provide functionality to define and validate the initialization arguments of a class in an easy way. e.g.

class MyClass
  include Definition::Initializer

  required :username, Definition.Type(String)
  optional :scores, Definition.Type(Array)

  def hello
    puts "Hello #{username}"
  end
end

instance = MyClass.new(username: "Fred", scores: [1,2,3])
instance.hello # => "Hello Fred"

this would only support keyword arguments though

Feedback welcome :)