Class: Hamster::Set

Inherits:
Object show all
Defined in:
lib/nrser/gem_ext/hamster/set.rb

Overview

Definitions

Direct Known Subclasses

I8::Set

Instance Method Summary collapse

Instance Method Details

#as_json(options = nil) ⇒ Object



53
54
55
56
# File 'lib/nrser/gem_ext/hamster/set.rb', line 53

def as_json options = nil
  to_mutable_array.to_json options
  # { '$set' => to_h.as_json( options ) }
end

#to_hObject



48
49
50
# File 'lib/nrser/gem_ext/hamster/set.rb', line 48

def to_h
  each_with_object( {} ) { |member, hash| hash[member] = true }
end

#to_mutableObject

Instance Methods



34
35
36
37
38
# File 'lib/nrser/gem_ext/hamster/set.rb', line 34

def to_mutable
  each_with_object( ::Set[] ) { |member, set|
    set << Hamster.to_mutable( member )
  }
end

#to_mutable_arrayObject



41
42
43
44
45
# File 'lib/nrser/gem_ext/hamster/set.rb', line 41

def to_mutable_array
  each_with_object( [] ) { |member, array|
    array << Hamster.to_mutable( member )
  }
end

#to_yaml(*args, &block) ⇒ Object



59
60
61
# File 'lib/nrser/gem_ext/hamster/set.rb', line 59

def to_yaml *args, &block
  to_mutable.to_yaml *args, &block
end