Module: SuperStruct

Defined in:
lib/super_struct.rb,
lib/super_struct/version.rb

Defined Under Namespace

Modules: InstanceMethods

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.new(array_or_hash, &block) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/super_struct.rb', line 25

def self.new(array_or_hash, &block)
  keys = if array_or_hash.respond_to?(:has_key?)
    array_or_hash.keys.sort.map(&:to_sym)
  else
    array_or_hash.sort.map(&:to_sym)
  end

  Struct.new(*keys, &block).tap do |struct|
    struct.send(:include, InstanceMethods)
  end
end