Training, Open Source Programming Languages

This is page http://www.wellho.net/resources/ex.php

Our email: info@wellho.net • Phone: 01144 1225 708225

 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Application to call in group of classes from a library file
this example from a Well House Consultants training course
More on this [link]

This example is described in the following article(s):
   • Clear, concise examples - Ruby classes and objects. - [link]

Source code: obrub4.rb Module: R102
# Call in class from another file in the same directory!

require "#{File.dirname(__FILE__)}/trainclass4"

# Let's put in something to look after a decent rail SERVICE!

services = []

for hour in 6 .. 21
        services.push Train.new "Swindon", 2, "150", "#{hour}:44"
        services.push Bus.new "Chippenham",3,"Optare","#{hour}:various"
end
for hour in 7 .. 22
        services.push Train.new "Westbury", 2, "150", "#{hour}:35"
        services.push Bus.new "Frome",2,"Optare","#{hour}:various"
        services.push Bus.new "Trowbridge",1,"Optare","#{hour}:various"
end

# Typically you would read lines in a know format from a file or database
linefromfile = "Badgerline\t07:15\tBowerhill\t66"

services.push Transport.factory linefromfile

for option in services
        nbums = option.getseats
        crewe = option.getdrivers
        puts "We can carry away #{nbums} on the thing from #{option.getstart} at " +
                "#{option.gettime}; staff = #{crewe}"
        puts option
end

counter = Transport.getcount
puts "A total of #{counter} options"

__END__

Sample Output

WomanWithCat:r102 grahamellis$ ruby obrub4.rb
We can carry away 146 on the thing from Swindon at 6:44; staff = 1
#<Train:0x007fb07992fe10>
We can carry away 183 on the thing from Chippenham at 6:various; staff = 3
It's a bus! ... leaves at 6:various
We can carry away 146 on the thing from Swindon at 7:44; staff = 1
#<Train:0x007fb07992fc80>
We can carry away 183 on the thing from Chippenham at 7:various; staff = 3
It's a bus! ... leaves at 7:various
We can carry away 146 on the thing from Swindon at 8:44; staff = 1
#<Train:0x007fb07992faf0>
We can carry away 183 on the thing from Chippenham at 8:various; staff = 3
It's a bus! ... leaves at 8:various
We can carry away 146 on the thing from Swindon at 9:44; staff = 1
#<Train:0x007fb07992f960>
We can carry away 183 on the thing from Chippenham at 9:various; staff = 3
It's a bus! ... leaves at 9:various
We can carry away 146 on the thing from Swindon at 10:44; staff = 1
#<Train:0x007fb07992f7d0>
We can carry away 183 on the thing from Chippenham at 10:various; staff = 3
It's a bus! ... leaves at 10:various
We can carry away 146 on the thing from Swindon at 11:44; staff = 1
#<Train:0x007fb07992f640>
We can carry away 183 on the thing from Chippenham at 11:various; staff = 3
It's a bus! ... leaves at 11:various
We can carry away 146 on the thing from Swindon at 12:44; staff = 1
#<Train:0x007fb07992f4b0>
We can carry away 183 on the thing from Chippenham at 12:various; staff = 3
It's a bus! ... leaves at 12:various
We can carry away 146 on the thing from Swindon at 13:44; staff = 1
#<Train:0x007fb07992f320>
We can carry away 183 on the thing from Chippenham at 13:various; staff = 3
It's a bus! ... leaves at 13:various
We can carry away 146 on the thing from Swindon at 14:44; staff = 1
#<Train:0x007fb07992f190>
We can carry away 183 on the thing from Chippenham at 14:various; staff = 3
It's a bus! ... leaves at 14:various
We can carry away 146 on the thing from Swindon at 15:44; staff = 1
#<Train:0x007fb07992f000>
We can carry away 183 on the thing from Chippenham at 15:various; staff = 3
It's a bus! ... leaves at 15:various
We can carry away 146 on the thing from Swindon at 16:44; staff = 1
#<Train:0x007fb07992ee70>
We can carry away 183 on the thing from Chippenham at 16:various; staff = 3
It's a bus! ... leaves at 16:various
We can carry away 146 on the thing from Swindon at 17:44; staff = 1
#<Train:0x007fb07992ece0>
We can carry away 183 on the thing from Chippenham at 17:various; staff = 3
It's a bus! ... leaves at 17:various
We can carry away 146 on the thing from Swindon at 18:44; staff = 1
#<Train:0x007fb07992eb50>
We can carry away 183 on the thing from Chippenham at 18:various; staff = 3
It's a bus! ... leaves at 18:various
We can carry away 146 on the thing from Swindon at 19:44; staff = 1
#<Train:0x007fb07992e9c0>
We can carry away 183 on the thing from Chippenham at 19:various; staff = 3
It's a bus! ... leaves at 19:various
We can carry away 146 on the thing from Swindon at 20:44; staff = 1
#<Train:0x007fb07992e830>
We can carry away 183 on the thing from Chippenham at 20:various; staff = 3
It's a bus! ... leaves at 20:various
We can carry away 146 on the thing from Swindon at 21:44; staff = 1
#<Train:0x007fb07992e6a0>
We can carry away 183 on the thing from Chippenham at 21:various; staff = 3
It's a bus! ... leaves at 21:various
We can carry away 146 on the thing from Westbury at 7:35; staff = 1
#<Train:0x007fb07992e510>
We can carry away 122 on the thing from Frome at 7:various; staff = 2
It's a bus! ... leaves at 7:various
We can carry away 61 on the thing from Trowbridge at 7:various; staff = 1
It's a bus! ... leaves at 7:various
We can carry away 146 on the thing from Westbury at 8:35; staff = 1
#<Train:0x007fb07992e2b8>
We can carry away 122 on the thing from Frome at 8:various; staff = 2
It's a bus! ... leaves at 8:various
We can carry away 61 on the thing from Trowbridge at 8:various; staff = 1
It's a bus! ... leaves at 8:various
We can carry away 146 on the thing from Westbury at 9:35; staff = 1
#<Train:0x007fb07992e060>
We can carry away 122 on the thing from Frome at 9:various; staff = 2
It's a bus! ... leaves at 9:various
We can carry away 61 on the thing from Trowbridge at 9:various; staff = 1
It's a bus! ... leaves at 9:various
We can carry away 146 on the thing from Westbury at 10:35; staff = 1
#<Train:0x007fb07992de08>
We can carry away 122 on the thing from Frome at 10:various; staff = 2
It's a bus! ... leaves at 10:various
We can carry away 61 on the thing from Trowbridge at 10:various; staff = 1
It's a bus! ... leaves at 10:various
We can carry away 146 on the thing from Westbury at 11:35; staff = 1
#<Train:0x007fb07992dbb0>
We can carry away 122 on the thing from Frome at 11:various; staff = 2
It's a bus! ... leaves at 11:various
We can carry away 61 on the thing from Trowbridge at 11:various; staff = 1
It's a bus! ... leaves at 11:various
We can carry away 146 on the thing from Westbury at 12:35; staff = 1
#<Train:0x007fb07992d958>
We can carry away 122 on the thing from Frome at 12:various; staff = 2
It's a bus! ... leaves at 12:various
We can carry away 61 on the thing from Trowbridge at 12:various; staff = 1
It's a bus! ... leaves at 12:various
We can carry away 146 on the thing from Westbury at 13:35; staff = 1
#<Train:0x007fb07992d700>
We can carry away 122 on the thing from Frome at 13:various; staff = 2
It's a bus! ... leaves at 13:various
We can carry away 61 on the thing from Trowbridge at 13:various; staff = 1
It's a bus! ... leaves at 13:various
We can carry away 146 on the thing from Westbury at 14:35; staff = 1
#<Train:0x007fb07992d4a8>
We can carry away 122 on the thing from Frome at 14:various; staff = 2
It's a bus! ... leaves at 14:various
We can carry away 61 on the thing from Trowbridge at 14:various; staff = 1
It's a bus! ... leaves at 14:various
We can carry away 146 on the thing from Westbury at 15:35; staff = 1
#<Train:0x007fb07992d250>
We can carry away 122 on the thing from Frome at 15:various; staff = 2
It's a bus! ... leaves at 15:various
We can carry away 61 on the thing from Trowbridge at 15:various; staff = 1
It's a bus! ... leaves at 15:various
We can carry away 146 on the thing from Westbury at 16:35; staff = 1
#<Train:0x007fb07992cff8>
We can carry away 122 on the thing from Frome at 16:various; staff = 2
It's a bus! ... leaves at 16:various
We can carry away 61 on the thing from Trowbridge at 16:various; staff = 1
It's a bus! ... leaves at 16:various
We can carry away 146 on the thing from Westbury at 17:35; staff = 1
#<Train:0x007fb07992cda0>
We can carry away 122 on the thing from Frome at 17:various; staff = 2
It's a bus! ... leaves at 17:various
We can carry away 61 on the thing from Trowbridge at 17:various; staff = 1
It's a bus! ... leaves at 17:various
We can carry away 146 on the thing from Westbury at 18:35; staff = 1
#<Train:0x007fb07992cb48>
We can carry away 122 on the thing from Frome at 18:various; staff = 2
It's a bus! ... leaves at 18:various
We can carry away 61 on the thing from Trowbridge at 18:various; staff = 1
It's a bus! ... leaves at 18:various
We can carry away 146 on the thing from Westbury at 19:35; staff = 1
#<Train:0x007fb07992c8f0>
We can carry away 122 on the thing from Frome at 19:various; staff = 2
It's a bus! ... leaves at 19:various
We can carry away 61 on the thing from Trowbridge at 19:various; staff = 1
It's a bus! ... leaves at 19:various
We can carry away 146 on the thing from Westbury at 20:35; staff = 1
#<Train:0x007fb07992c698>
We can carry away 122 on the thing from Frome at 20:various; staff = 2
It's a bus! ... leaves at 20:various
We can carry away 61 on the thing from Trowbridge at 20:various; staff = 1
It's a bus! ... leaves at 20:various
We can carry away 146 on the thing from Westbury at 21:35; staff = 1
#<Train:0x007fb07992c440>
We can carry away 122 on the thing from Frome at 21:various; staff = 2
It's a bus! ... leaves at 21:various
We can carry away 61 on the thing from Trowbridge at 21:various; staff = 1
It's a bus! ... leaves at 21:various
We can carry away 146 on the thing from Westbury at 22:35; staff = 1
#<Train:0x007fb07992c1e8>
We can carry away 122 on the thing from Frome at 22:various; staff = 2
It's a bus! ... leaves at 22:various
We can carry away 61 on the thing from Trowbridge at 22:various; staff = 1
It's a bus! ... leaves at 22:various
We can carry away 61 on the thing from Bowerhill at 07:15; staff = 1
It's a bus! ... leaves at 07:15
A total of 81 options
WomanWithCat:r102 grahamellis$

Learn about this subject
This module and example are covered as required on private courses. Should you wish to cover this example and associated subjects, and you're attending a public course to cover other topics with us, please see our extra topic program.

Books covering this topic
Yes. We have over 700 books in our library. Books covering Ruby are listed here and when you've selected a relevant book we'll link you on to Amazon to order.

Other Examples
This example comes from our "this" training module. You'll find a description of the topic and some other closely related examples on the "this" module index page.

Full description of the source code
You can learn more about this example on the training courses listed on this page, on which you'll be given a full set of training notes.

Many other training modules are available for download (for limited use) from our download centre under an Open Training Notes License.

Other resources
• Our Solutions centre provides a number of longer technical articles.
• Our Opentalk forum archive provides a question and answer centre.
The Horse's mouth provides a daily tip or thought.
• Further resources are available via the resources centre.
• All of these resources can be searched through through our search engine
• And there's a global index here.

Web site author
This web site is written and maintained by Well House Consultants.

Purpose of this website
This is a sample program, class demonstration or answer from a training course. It's main purpose is to provide an after-course service to customers who have attended our public private or on site courses, but the examples are made generally available under conditions described below.

Conditions of use
Past attendees on our training courses are welcome to use individual examples in the course of their programming, but must check the examples they use to ensure that they are suitable for their job. Remember that some of our examples show you how not to do things - check in your notes. Well House Consultants take no responsibility for the suitability of these example programs to customer's needs.

This program is copyright Well House Consultants Ltd. You are forbidden from using it for running your own training courses without our prior written permission. See our page on courseware provision for more details.

Any of our images within this code may NOT be reused on a public URL without our prior permission. For Bona Fide personal use, we will often grant you permission provided that you provide a link back. Commercial use on a website will incur a license fee for each image used - details on request.

© WELL HOUSE CONSULTANTS LTD., 2024: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/resources/ex.php • PAGE BUILT: Sun Oct 11 14:50:09 2020 • BUILD SYSTEM: JelliaJamb