![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | ||||||
|
Hobbyist Programmer
Join Date: Jul 2004
Location: Location
Posts: 138
Rep Power: 5
![]() |
Ruby Classes tutorial
I created a tutorial to help me while learning Ruby. I've decided to post it for all to see
Please let me know of any syntax errors if you see them, so I may fix them.Classes Library example: Ok, so I want to start a library. In the library, I need books. We need to make a basic class, books. This is where all the books will go. We'll start off by creating a basic class for all the books. Quote:
Now lets enter a book into the database: Quote:
Now we want to try and get all the book information. So we will do this: Quote:
Quote:
Inheritance and Messages Inheritance allows you to create a class that is a specialization of another class. (Think of it as a subclass). For example, our library has the book conecept class Books. Now we will make a specific class for a genre of book. Quote:
Note: < Tells ruby that ProgrammingBooks is a subclass of Books. Quote:
**Note * You can get info using things such as Book.name etc. what ever comes after the . is a variable that you've set. |
||||||
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4
![]() |
Should the line
book1 = Book.new("Ruby Guide","2005","bulio")book1 = Books.new("Ruby Guide","2005","bulio")edit: Maybe fix the indenting also? Last edited by Cerulean; Aug 11th, 2005 at 3:50 PM. |
|
|
|
|
|
#3 |
|
Expert Programmer
|
Nice that tutorial is clear and understandable, i don't know any Ruby, but this has shown me what it is like. I would hve tested it all out, but atm i am learning python GUI and network programming, so i would probably get confused and muddled up lol.
Good tutorial. |
|
|
|
|
|
#4 |
|
Programming Guru
![]() ![]() ![]() |
looks good. are you planning on extending this tutorial to cover other areas?
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: Jul 2004
Location: Location
Posts: 138
Rep Power: 5
![]() |
I'll probably cover more as I go along, yes but for now I need to learn more
![]() |
|
|
|
|
|
#6 |
|
Newbie
Join Date: Oct 2005
Posts: 5
Rep Power: 0
![]() |
gud job done m8
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|