Module: SuperStruct

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

Defined Under Namespace

Modules: InstanceMethods

Constant Summary collapse

VERSION =
"0.0.5"

Class Method Summary collapse

Class Method Details

.from_hash(hash, &block) ⇒ Object



51
52
53
# File 'lib/super_struct.rb', line 51

def self.from_hash(hash, &block)
  new(hash, &block).new(hash)
end

.new(*input, &block) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/super_struct.rb', line 39

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

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