Sha256: 09374c42929fa51180bff29a872d955e0be8ba8e283b0430772d26b0ea64467c

Contents?: true

Size: 456 Bytes

Versions: 5

Compression:

Stored size: 456 Bytes

Contents

# frozen_string_literal: true

module Polist
  module Struct
    module ClassMethods
      def struct(*attrs)
        attr_accessor(*attrs)

        define_method(:initialize) do |*args|
          raise ArgumentError, "struct size differs" if args.length > attrs.length
          attrs.zip(args).each { |attr, val| public_send(:"#{attr}=", val) }
        end
      end
    end

    def self.included(base)
      base.extend(ClassMethods)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
polist-1.4.0 lib/polist/struct.rb
polist-1.2.0 lib/polist/struct.rb
polist-1.1.1 lib/polist/struct.rb
polist-1.1.0 lib/polist/struct.rb
polist-1.0.0 lib/polist/struct.rb