Class: Struct::Initializer::Definition
- Inherits:
-
Module
- Object
- Module
- Struct::Initializer::Definition
- Defined in:
- lib/struct/initializer.rb
Instance Method Summary collapse
-
#initialize(names, keyword_init: false) ⇒ Definition
constructor
A new instance of Definition.
Constructor Details
#initialize(names, keyword_init: false) ⇒ Definition
Returns a new instance of Definition.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/struct/initializer.rb', line 8 def initialize(names, keyword_init: false) attr_reader(*names) arguments = names.map { "#{_1}#{":" if keyword_init}" }.join(", ") class_eval <<~RUBY, __FILE__, __LINE__ + 1 def initialize(#{arguments}) #{names.map { "@#{_1} = #{_1}" }.join("\n")} end RUBY end |