Class: BiblioRefs::List
- Inherits:
-
Object
- Object
- BiblioRefs::List
- Includes:
- Enumerable
- Defined in:
- lib/biblio_refs/list.rb
Instance Attribute Summary collapse
-
#head ⇒ Object
Returns the value of attribute head.
-
#tail ⇒ Object
Returns the value of attribute tail.
Instance Method Summary collapse
-
#each {|aux[:value]| ... } ⇒ Object
Método que recorre todos los valores de los nodos de la lista Necesario para hacer la clase List enumerable, haciendo ‘yield’ a todos los valores.
-
#initialize(*nodo) ⇒ List
constructor
Constructor de la clase List.
-
#pop ⇒ Object
Método que devuelve y extrae el valor del primer nodo de la lista.
-
#push(*nodo) ⇒ Object
Método que inserta uno o varios nodos al final de la lista.
-
#to_s ⇒ Object
Método que devuelve una cadena de carácteres formateada de los objetos de la clase List.
Constructor Details
Instance Attribute Details
#head ⇒ Object
Returns the value of attribute head.
8 9 10 |
# File 'lib/biblio_refs/list.rb', line 8 def head @head end |
#tail ⇒ Object
Returns the value of attribute tail.
8 9 10 |
# File 'lib/biblio_refs/list.rb', line 8 def tail @tail end |
Instance Method Details
#each {|aux[:value]| ... } ⇒ Object
Método que recorre todos los valores de los nodos de la lista Necesario para hacer la clase List enumerable, haciendo ‘yield’ a todos los valores
21 22 23 24 25 26 27 28 |
# File 'lib/biblio_refs/list.rb', line 21 def each aux = @head while aux[:next] yield aux[:value] aux = aux[:next] end yield aux[:value] end |
#pop ⇒ Object
Método que devuelve y extrae el valor del primer nodo de la lista
31 32 33 34 35 |
# File 'lib/biblio_refs/list.rb', line 31 def pop nodo = @head @head = @head[:next] nodo[:value] end |
#push(*nodo) ⇒ Object
Método que inserta uno o varios nodos al final de la lista
38 39 40 41 42 43 44 45 46 |
# File 'lib/biblio_refs/list.rb', line 38 def push(*nodo) aux = @head nodo.each do |n| while aux[:next] do aux = aux[:next] end @tail = aux[:next] = Nodo.new(n, nil, aux) end end |
#to_s ⇒ Object
Método que devuelve una cadena de carácteres formateada de los objetos de la clase List
49 50 51 52 53 54 55 56 57 |
# File 'lib/biblio_refs/list.rb', line 49 def to_s aux = @head string = "Lista: " while aux[:next] do string += "#{aux[:value]}" + " -> " aux = aux[:next] end string += "#{aux[:value]}" end |