It might be almost similar but relatively different in a big way for blocks may appear only in the source adjacent to a method call which means it should be written on the same line as the method’s last parameter and it is not implemented once it is encountered but, Ruby rather remembers the context [...]
Category Archives: Programming Basics
The ‘if’ Statement
As stated in the past post, we aim to simplify further the code we have just created with the following shorter version of the same program. class BookList def [](key) if key.kind_of?(integer) result = @Books[key] else result = @Books.find { |aBooks| key == sBooks.name} end return result end end Further shortening the code we have [...]
The [] method
We now go through a process which implements the code on the [] method we just showed where we will take a string, searches for the book with the same title. The method would go through the whole table one at a time to get a match as shown with the following: class BookList def [...]
RoR Naming Conventions
Some more basics or building blocks to better understand ruby, one of which is the naming convention used by the language. The first characters of a name shows how that specific name was used. Local variables, method names and method Parameters always start with either lowercase characters or an underscore. Global variables should always be [...]
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 [...]
Empty arrays and Shortcuts
In the last post, we created arrays and showed how the various elements could be accessed or the contents changed. Now, we will create empty arrays which would be useful for easy tracing of code when you start building whole projects. To create an empty array with no elements or by using the array object’s [...]
RoR Arrays and Hashes
An array is a table or indexed collection that needs an integer key to point to a specific set of information contained within the said table. A hash on the other hand, supports any object as a key meaning it can be numeric, character or alphanumeric to name some. To initiate a new array you [...]
Back to Basics
Now, for those who do not have any idea what we are doing as of now, better begin again from the start. The term “Easy to Learn” doesn’t mean that you get all the stuff into your head in a couple of minutes. While it is true that there are several claims of getting you [...]
Getting started
Ruby on rails can be downloaded from many sources over the internet like from http://api.rubyonrails.org/ where there are also instructions on how to quickly install and start programming. The first lessons would be the forever basic “Hello World” program which is very easy if you get set-up right. For a more automated installation you could [...]