Exercises, examples and other material relating to training module R110. This topic is presented on public courses Learning to program in Ruby
, Ruby Programming
Every operation has a result. Easy - store it to
a varibale. But operations have side effects too that
you can read from special variables. And the very act
of running your script provides a wide variety of extra
information that you may want to use ... and is there,
if you know where, for the asking.
Related technical and longer articlesSolution Centre - all article listingSolution Centre - all article listing
|Articles and tips on this subject||updated|
|3757||Ruby - a teaching example showing many of the language features in short but useful program|
Although the main publicity and driver for the Ruby language has been the Rails web framework (see previous article here), it's an excellent data manipulation language too - with many of the short and efficient coding techniques that you would have available to you in Perl, yet additionally with an object ...
|2623||Object Oriented Ruby - new examples|
We had an "object oriented Ruby" morning on today's course. "But everything's an object in Ruby" you'll tell me and you're sort of right (we could argue about what symbols and code blocks are), but there are certain elements of object orientation which require specific coverage.
Here are links to three ...
|2613||Constants in Ruby|
If you want to have a read only variable in Ruby, start its name with a capital letter (and you may like to go with a convention of using capitals right through the variable name).
Note that a Ruby constant - a name starting with a capital - hasa global scope, just like a variable name that starts with ...
|2296||Variable scope - what is it, and how does it Ruby?|
Variables have different "scopes" - in other words, a name that is allocated to a piece of computer memory and subsequently used to refer to that memory may be 'know about" to your program only within a very small area, or much more widely. It's the same IRL ("In Real Life") - consider you, Dad, Graham ...
|1891||Ruby to access web services|
If you want to use a Ruby program to access an RSS feed (or some other XML or HTML data), you can start with the standard Net::HTTP module ... full (working, tested) example here. That example "just" uses a Get method to get an RSS feed of the latest posts to the First Great Western Coffee Shop Forum ...
|1586||Variable types in Ruby|
* Variable with names starting with a lower case letter are local variables
* Names starting with a capital letter are constants - you can set them once each time you run a program and then they are fixed
* Names starting with a single @ character are object variables - in other words, you'll ...
|1587||Some Ruby programming examples from our course|
I was giving a Public Ruby Course to a small group at the end of last week ... and having a small group gave me the opportunity to write some demonstrations in front of them. I have now tidied these up and have pleasure in presenting to more Ruby demonstrations:
Ruby's BEGIN block
The compact method ...
|990||Ruby - Totally Topical|
Ruby supports topicalisation - the $_ variable being set by certain statements when a piece of code such as gets in a while statement isn't assigned, and the the same variable being used in many other methods - and even as the object on which methods run by default - in following code.
Here's a piece ...
Examples from our training material
|answer|| Data manipulation example (table inversion) |
|av|| Command Line Parameters to a Ruby program|
|c3.rb|| Process every line via topicalisation|
|cc|| begin block|
|gloop1|| Topicalisation - before|
|gloop2|| Topicalisation - after |
|pgv.rb|| Predefined global variables and resources |
|rerub|| Cleaning an incoming string in Ruby|
|ruby_awk.rb|| implicit loop around code - awk mode|
|tiny|| Autosplit mode, a loop round your code, BEGIN and END|
|topic.rb|| Topicalisation - the use of $_|
|vvx|| variable types |
Some modules are available for download
as a sample of our material or under an Open Training Notes License
for free download from http://www.training-notes.co.uk
Topics covered in this module
ARGV, $0 and friends - the command line.
Other special variables from $: through $$ to $<.
Reserved words in Ruby.
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. Also
available is the Opentalk
Forum for discussion of technical questions.