0.0
No commit activity in last 3 years
No release in over 3 years
Simple Struct with required keyword arguments
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

NamedStruct Build Status Code Climate

Simple object to wrap your configuration, it can be instantiated only with required named arguments.

Usually you do :

class MyConfig
  att_reader :a, :b, :c

  def initialize(a:, b:, c:)
    @a = a
    @b = b
    @c = c
  end

end

But now you can :

class MyConfig < NamedStruct::Config
   attr_required :a, :b, :c
end

Installation

Add this line to your application's Gemfile:

gem 'named_struct'

And then execute:

$ bundle

Or install it yourself as:

$ gem install named_struct

Usage

require 'named_struct'

class MyConfig < NamedStruct::Config
   attr_required :a, :b, :c
end

my_config = MyConfig.new(a: 10, b: 20, c: 30)

class MySuperAlgorithm
   def initialize(my_param, **config)
      @my_param = my_param
      @config = MyConfig.new(**config)
   end
end

MySuperAlgirithm.new("some param", a: 12, b: 10, c: 50)