Exercises, examples and other material relating to training module R105. This topic is presented on public courses
Learning to program in Ruby,
Ruby Programming
Background
Let's introduce you to Ruby's
powerful OO model - it's quick,
easy, effective and extensible.
Related technical and longer articles
Basic class definition and use in Ruby
Articles and tips on this subject | updated |
4502 | 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, ... | 2015-06-02 |
4009 | 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 ... | 2013-02-17 |
3421 | 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 ... | 2013-01-01 |
2651 | 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 ... | 2010-03-03 |
2616 | 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 ... | 2010-02-01 |
2609 | 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 ... | 2010-01-31 |
2603 | 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 ... | 2010-01-29 (longer) |
2292 | 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 ... | 2009-07-17 |
1925 | 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, ... | 2008-12-10 (longer) |
983 | 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.
Perl:
bless \%abc;
Ruby:
@abc ... | 2006-12-14 (short) |
Examples from our training material
disc | How to define and use a class |
dp.rb | Just define a class for use elsewhere |
mm.rb | Accessing class variables, and adding methods |
myo.rb | Define and use a class |
obtest.rb | Static (class) method definition and use |
stan.rb | Standard methods! |
thapp.rb | Call in a class from another file |
tharn.rb | A class with a test harness |
thirdrail | File -> Objects -> Analysis |
tj2.rb | Displaying via an Inset class |
train.rb | Sample class with accessors and comparator methods |
triang.rb | Simple class and use |
ucl.rb | Use a class defined in another file |
Background information
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.
Complete learning
If you are looking for a complete course and not just a information on a single subject, visit our
Listing and schedule page.
Well House Consultants specialise in training courses in
Ruby,
Lua,
Python,
Perl,
PHP, and
MySQL. We run
Private Courses throughout the UK (and beyond for longer courses), and
Public Courses 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.