Sha256: fdaf07d9befb9b7a14ad05aa96fa6a095d31313533fb86c0ec8610e04783fa96

Contents?: true

Size: 698 Bytes

Versions: 8

Compression:

Stored size: 698 Bytes

Contents

module Yaoc
  module Helper
    module StructHashConstructor
      def self.included(klass)
        klass.send :prepend, Initializer
      end

      module Initializer
        def initialize(params={})
          super()

          params.each do |attr, value|
            self.public_send("#{attr}=", value)
          end if params
        end
      end
    end

    module_function
    def StructH(*args, &block)
      Struct.new(*args, &block).tap do|new_class|
        new_class.send(:include, Yaoc::Helper::StructHashConstructor)
      end
    end

    def StructHE(*args, &block)
      StructH(*args, &block).tap do|new_class|
        include Equalizer.new(*args)
      end
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
yaoc-0.0.13 lib/yaoc/helper/struct_hash_constructor.rb
yaoc-0.0.12 lib/yaoc/helper/struct_hash_constructor.rb
yaoc-0.0.11 lib/yaoc/helper/struct_hash_constructor.rb
yaoc-0.0.10 lib/yaoc/helper/struct_hash_constructor.rb
yaoc-0.0.9 lib/yaoc/helper/struct_hash_constructor.rb
yaoc-0.0.8 lib/yaoc/helper/struct_hash_constructor.rb
yaoc-0.0.7 lib/yaoc/helper/struct_hash_constructor.rb
yaoc-0.0.6 lib/yaoc/helper/struct_hash_constructor.rb