Exercises, examples and other material relating to training module R110. This topic is presented on public courses
Learning to program in Ruby,
Ruby Programming
Background
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 articles
Solution Centre - all article listingSolution Centre - all article listing
Articles and tips on this subject | updated |
4682 | One line scripts - Awk, Perl and Ruby The art of the one line script, originating in awk and passing through Perl lives on in Ruby!
WomanWithCat:4c grahamellis$ awk '/Upper/{c++}; END { print(c,"of",NR)}; BEGIN {c=0}' rstats2015.txt
5 of 2537
WomanWithCat:4c grahamellis$
WomanWithCat:4c grahamellis$ ... | 2016-05-20 |
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 |
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 ... | 2012-06-16 (longest) |
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 ... | 2010-02-04 |
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 ... | 2010-02-01 (short) |
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 ... | 2009-07-19 |
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 ... | 2008-11-16 |
1586 | Variable types in Ruby 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 ... | 2008-03-22 |
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 ... | 2008-03-21 |
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 ... | 2006-12-16 |
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 |
envx | reading and setting environment variables from and for shell commands |
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 |
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
ARGV, $0 and friends - the command line.
Other special variables from $: through $$ to $<.
Environment variables.
Pseudo-variables.
Reserved words in Ruby.
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.