Module: Notcurses::SwigMixins::StructInitializer

Defined in:
lib/notcurses/swig_mixins/struct_initializer.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/notcurses/swig_mixins/struct_initializer.rb', line 4

def self.included(base)
  base.class_eval do
    alias_method :swig_initialize, :initialize

    def initialize(**options)
      swig_initialize

      options.each do |k, v|
        setter = "#{k}="

        unless respond_to?(setter)
          raise ArgumentError, "Unknown attribute: #{k}"
        end

        send(setter, v)
      end
    end
  end
end