Class: OAuthActiveResource::UniqueArray

Inherits:
Array
  • Object
show all
Defined in:
lib/oauth_active_resource/unique_resource_array.rb

Direct Known Subclasses

UniqueResourceArray

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ UniqueArray

Returns a new instance of UniqueArray.



5
6
7
8
9
10
11
# File 'lib/oauth_active_resource/unique_resource_array.rb', line 5

def initialize(*args)
  if args.size == 1 and args[0].is_a? Array then
    super(args[0].uniq)
  else
    super(*args)
  end
end

Instance Method Details

#<<(v) ⇒ Object



17
18
19
# File 'lib/oauth_active_resource/unique_resource_array.rb', line 17

def <<(v)
  super(v) unless include?(v)
end

#[]=(*args) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/oauth_active_resource/unique_resource_array.rb', line 21

def []=(*args)
  # note: could just call super(*args) then uniq!, but this is faster

  # there are three different versions of this call:
  # 1. start, length, value
  # 2. index, value
  # 3. range, value
  # We just need to get the value
  v = case args.size
    when 3 then args[2]
    when 2 then args[1]
    else nil
  end

  super(*args) if v.nil? or not include?(v)
end

#insert(i, v) ⇒ Object



13
14
15
# File 'lib/oauth_active_resource/unique_resource_array.rb', line 13

def insert(i, v)
  super(i, v) unless include?(v)
end