Tag Archives: Sample Code

Simplifying the code

We now check if the book titles are deleted from the first and end of the list which should give us ‘nil’ when and if the list becomes void of contents.
list.deleteFirst >> Books: ABDC–Author1 (1)
list.deleteFirst >> Books: EFGH–Author2 (2)
list.deleteLast >> Books: MNOP–Author1 (1)
list.deleteLast >> Books: IJKL–Author3 (3)
list.deleteLast >> nil
We now include the use of the square brackets which allows [...]

Posted in Development, Programming Basics | Also tagged , | Comments closed

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 [...]

Posted in Development, Programming Basics | Also tagged | Comments closed

Blocks – Example

Below, we find sample code which uses block to return the values of the Fibonacci number Series.
def fibMax(max)
a1, a2 =1,1 # variables that are assigned parallel values
while a1

Posted in Development, Programming Basics | Also tagged | Comments closed

Container Creation

To initialize a container we will do the same steps showing code to support the things that have to be done. We create a table where we can add elements to the contents delete objects from either the beginning or the last entries and display an entry using the index or content on the index. [...]

Posted in Development, Programming Basics | Also tagged | Comments closed