Exercises, examples and other material relating to training module R103. This topic is presented on public courses
Learning to program in Ruby,
Ruby Programming
Background
Ruby hasn't re-invented everything - it's taken
the good basics from variables through "Bodmas" to
statement structure and commenting from best practise
elsewhere.
| Articles and tips on this subject | updated |
| 3430 | Sigils - the characters on the start of variable names in Perl, Ruby and Fortran A sigil (from Latin sigillum "seal") is a symbol created for a specific magical purpose. A sigil is usually made up of a complex combination of several specific symbols or geometric figures, each with a specific meaning or intent. In computer programming, a sigil is a special symbol attached to a variable ... | 2011-09-10 |
| 3278 | Do I need to initialise variables - programming in C, C++, Perl, PHP, Python, Ruby or Java. Starting with a clean slate. Are variables initisialised, and if so, how? Even with this fundamental question, languages vary considerably.
C and C++
From my (e)mailbag ...
"""In a piece of code we’ve written we declare an array, but we do not fill the elements with values, we assume (dangerous ... | 2011-05-05 |
| 2617 | Comparing floating point numbers - a word of caution and a solution "Think of a number between 5 and 15.
Double it.
Add fourteen.
Halve it.
Take away the number you first thought of.
Is the result 7?"
We all played games like that as children, thinking of the number 0 ourselves so that we could do an easy calculation and impress our friends. And the result was 7 ... ... | 2010-02-02 |
| 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 |
| 2287 | Learning to program in Ruby - examples of the programming basics We so often overlook the basics of programming, and yet they are so fundamental to good code - understanding things like how widely variables can be seen (also known as variable scope), what happens when you divide two numbers (do you get a decimal result or is the remainder thrown away), and how do ... | 2009-07-15 |
| 986 | puts - opposite of chomp in Ruby In Ruby, the chomp method removes the last character of a string if it's a line separator. The puts method adds a new line character on to the output unless there's one already present.
In Perl and other languages, a great deal of time and mental agility is expended in remembering where there are (and ... | 2006-12-15 (short) |
Examples from our training material
| bw.rb | Formatting strings and conversions |
| calc.rb | Some early gotchas! |
| calcbetter.rb | A simple calculation in Ruby |
| d2.4 | Easier output formatting in double quoted strings |
| d2.5 | Calculations within double quotes |
| floater | Floating point rounding errors |
| muck | Common Ruby Pitfalls |
| print.rb | Print alternatives |
| rub1 | FAILS to continue a line |
| x01 | Constants in Ruby |
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
http://www.training-notes.co.uk.
Topics covered in this module
Structure of statements and comments.
Variables and constants.
Operators.
Assignments, calculations, etc.
Integer, float and string formats.
Single and double quotes, here documents, general strings.
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
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. Also
available is the Opentalk
Forum for discussion of technical questions.