Sha256: d400994455de518789ab4118ff8ab7aa21c392fb771fd32a53142ad7e9f8f874

Contents?: true

Size: 528 Bytes

Versions: 3

Compression:

Stored size: 528 Bytes

Contents

module Usable
  def self.Struct(attributes = {})
    Class.new do
      extend Usable

      self.usables = Usable::Config.new(attributes)

      define_singleton_method(:inherited) do |child|
        child.usables = usables.clone
      end

      attributes.keys.each do |key|
        define_method(key) { @attrs[key] }
        define_method("#{key}=") { |new_val| @attrs[key] = new_val }
      end

      attr_accessor :attrs

      def initialize(attrs = {})
        @attrs = usables.merge(attrs)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
usable-3.5.0 lib/usable/struct.rb
usable-3.4.0 lib/usable/struct.rb
usable-3.3.0 lib/usable/struct.rb