Class: Ykutils::Hasharray

Inherits:
Hash
  • Object
show all
Defined in:
lib/ykutils/hasharray.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Hasharray

Returns a new instance of Hasharray.



3
4
5
6
7
8
# File 'lib/ykutils/hasharray.rb', line 3

def initialize(*args)
  super(*args)
  @ary = super.keys
  #    @ary ||= []
  @ary ||= []
end

Instance Method Details

#[]=(key, value) ⇒ Object



10
11
12
13
# File 'lib/ykutils/hasharray.rb', line 10

def []=(key, value)
  super(key, value)
  @ary << key unless @ary.index(key)
end

#clearObject



29
30
31
32
# File 'lib/ykutils/hasharray.rb', line 29

def clear
  super
  @ary = []
end

#delete(ind, &block) ⇒ Object



40
41
42
43
44
# File 'lib/ykutils/hasharray.rb', line 40

def delete(ind, &block)
  @ary.delete(ind)

  super
end

#delete_if(&block) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/ykutils/hasharray.rb', line 46

def delete_if(&block)
  @ary.each do |it|
    @ary.delete(it) if block.call(it, self[it])
  end

  super
end

#each(&block) ⇒ Object



15
16
17
18
19
# File 'lib/ykutils/hasharray.rb', line 15

def each(&block)
  @ary.each do |it|
    block.call(it, self[it])
  end
end

#keysObject



21
22
23
# File 'lib/ykutils/hasharray.rb', line 21

def keys
  @ary
end

#replace(*args) ⇒ Object



34
35
36
37
38
# File 'lib/ykutils/hasharray.rb', line 34

def replace(*args)
  super(*args)
  @ary = super.keys
  @replace ||= []
end

#valuesObject



25
26
27
# File 'lib/ykutils/hasharray.rb', line 25

def values
  @ary.collect { |it| self[it] }
end