123456789_123456789_123456789_123456789_123456789_

Class: Gem::List

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Struct
Instance Chain:
self, Struct
Inherits: Struct
  • Object
Defined in: lib/rubygems/util/list.rb,
lib/rubygems/util/list.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Class Method Details

.prepend(list, value)

[ GitHub ]

  
# 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 Attribute Details

#tail (rw)

[ GitHub ]

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

List = Struct.new(:value, :tail)

#value (rw)

[ GitHub ]

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

List = Struct.new(:value, :tail)

Instance Method Details

#each

[ GitHub ]

  
# File 'lib/rubygems/util/list.rb', line 5

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

#find

[ GitHub ]

  
# 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)

[ GitHub ]

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

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

#to_a

[ GitHub ]

  
# 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