Class: Gem::List

Inherits:
Struct
  • Object
show all
Defined in:
lib/rubygems/util/list.rb,
lib/rubygems/util/list.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#tailObject

Returns the value of attribute tail

Returns:

  • (Object)

    the current value of tail



2
3
4
# File 'lib/rubygems/util/list.rb', line 2

def tail
  @tail
end

#valueObject

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



2
3
4
# File 'lib/rubygems/util/list.rb', line 2

def value
  @value
end

Class Method Details

.prepend(list, value) ⇒ Object



43
44
45
46
# File 'lib/rubygems/util/list.rb', line 43

def self.prepend(list, value)
  return List.new(value) unless list
  List.new value, list
end

Instance Method Details

#eachObject



5
6
7
8
9
10
11
# File 'lib/rubygems/util/list.rb', line 5

def each
  n = self
  while n
    yield n.value
    n = n.tail
  end
end

#findObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/rubygems/util/list.rb', line 24

def find
  n = self
  while n
    v = n.value
    return v if yield(v)
    n = n.tail
  end

  nil
end

#prepend(value) ⇒ Object



35
36
37
# File 'lib/rubygems/util/list.rb', line 35

def prepend(value)
  List.new value, self
end

#pretty_print(q) ⇒ Object

:nodoc:



39
40
41
# File 'lib/rubygems/util/list.rb', line 39

def pretty_print q # :nodoc:
  q.pp to_a
end

#to_aObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/rubygems/util/list.rb', line 13

def to_a
  ary = []
  n = self
  while n
    ary.unshift n.value
    n = n.tail
  end

  ary
end