Append

Using the append command/method, we can add an element to the end of the table which in turn returns a reference to the current BookList object.The deleteFirst and deleteLast command allows us to delete the first and last records respectively in the following form/s:

For Append:
class BookList
def append(aBook)
@books.push(aBook)
self
end
end

For deleteFirst and deleteLast

class BookList
def deleteFirts
@books.shift
end
def deleteLast
@books.pop
end
end

Now we test the code we have just created to show if the right operations are being performed and if we are getting the results we desire:

list = BookList.new
list.
append(Books.new(‘ABCD’, ‘Author1′,1)).
append(Books.new(‘EFGH’, ‘Author2′,2)).
append(Books.new(‘IJKL’, ‘Author3′,3)).
append(Books.new(‘MNOP’, ‘Author4′,4))

In the next posts, we get to check and simplify the code we have just executed.

This entry was posted in Development, Programming Basics and tagged , . Bookmark the permalink. Comments are closed, but you can leave a trackback: Trackback URL.