Exercises, examples and other material relating to training module R105. This topic is presented on public courses Learning to program in Ruby
, Ruby Programming
Let's introduce you to Ruby's
powerful OO model - it's quick,
easy, effective and extensible.
Related technical and longer articlesBasic class definition and use in Ruby
|Articles and tips on this subject
|Reading and parsing a JSON object in Ruby
Here's a series of three new examples, building up from one another, showing the reading of a JSON feed from a remote web site in Ruby, and the analysis and presentation of that data.
The first example - [here] - shows the loading of extra modules to handle reading from the web and the JSON format, ...
|Clear, concise examples - Ruby classes and objects.
Finding clear, concise examples of how to perform a simple programming task can be surprisingly difficult. "I just want a [Rails] model that doesn't actually use a database table" was an example yesterday. Such shouldn't be difficult, but authors tend to write a simple example and then decide "While ...
|Ruby off the Rails?
Time was ... "if it's Ruby it must be Rails". The Ruby on Rails framework was the initial killer application that brought the Ruby language to the attention of many, and was so prevelant that it masked other excellent uses. So I'm delighted to see significant other uses of Ruby growing in addition ...
|Calculation within objects - early, last minute, or cached?
When you create an object with the constructor, you may also set property [attribute] values within it ... or you may follow on with a series of method calls to set the initial values. Then when you pull back values / attributes / properties from your object you return those values, or the results ...
|Defining a static method - Java, Python and Ruby
Most methods in classes that your write will be run on / applied to individual objects within that class - you'll be asking for the colour of a marker pen, or setting the price of a hotel room. You will NOT - typically - have a model in which all marker pens share the same colour.
But - just occasionally ...
|Scope of variables - important to Ruby on Rails
Yesterday's Ruby on Rails training day brought home just how important it is to ensure that your Ruby variables are correctly "scoped" - that you tell Ruby if they're to be local to the method in which they are defined, to be available to all methods that run on the same objects, to all objects of a ...
|Ruby objects - a primer
If you're new to Ruby, but familiar with Object Oriented Programming, you might like to take a quick look at the example that I wrote during yesterday's course which shows how all the major OO elements are implemented in Ruby. The sample source is [here].
Here are some of the key facts:
• Classes ...
|Object Orientation in Ruby - intermediate examples
It's when you teach object orientation - the fully Monty, including inheritance, static and dynamic methods and variables, and so on - to a complete novice to programming and that person finds it's one of the easiest parts of the course that you realise:
a) Just how many bad ole habits us ancient structure ...
|Introduction to Object Oriented Programming
"Object Oriented Programming" is a whole new philosophy for programmers who have been writing short scripts for years, and it can be quite frightening to learn with all these new buzzwords like "overriding", "encapsulation" and "polymorphism" creeping in. It's a beautiful concept and a lovely approach, ...
|Blessing in Perl / Member variable in Ruby
How do you decide what member variables you have in an object in Ruby? Well - in Perl, you bless a single hash (or, exceptionally, a list or a scaler), but in Ruby you refer to each variable that you wish to be a member of each object using a preceeding @ character.
Examples from our training material
| How to define and use a class
| Just define a class for use elsewhere
| Accessing class variables, and adding methods
| Define and use a class
| Static (class) method definition and use
| Standard methods!
| Call in a class from another file
| A class with a test harness
| File -> Objects -> Analysis
| Displaying via an Inset class
| Sample class with accessors and comparator methods
| Simple class and use
| Use a class defined in another file
Some modules are available for download
as a sample of our material or under an Open Training Notes License
for free download from [here]
Topics covered in this module
Objects, classes and methods.
Constructors and attributes.
Instance and class variables.
Local and global variables.
Class and object methods.
Including files - load and require.
If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule
Well House Consultants specialise in training courses in
. We run
throughout the UK (and beyond for longer courses), and
at our training centre in Melksham, Wiltshire, England.
It's surprisingly cost effective to come on our public courses -
even if you live in a different
country or continent to us
We have a technical library of over 700 books on the subjects on which we teach.
These books are available for reference at our training centre.