Main Content
Some Ruby programming examples from our course Archive - Originally posted on "The Horse's Mouth" - 2008-03-21 18:22:20 - Graham Ellis
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 - strips out nil members from an array
Writing comparator methods such as "larger" and "smaller" in Ruby
Using a hash to provide a table of counters
Calling another process via a pipe in Ruby
Definition and use of a class in Ruby
Definition and the redefinition of the same function in Ruby
Some other articles
R110 - Special Variables and Pseudo-Variables One line scripts - Awk, Perl and Ruby Reading and parsing a JSON object in Ruby Ruby - a teaching example showing many of the language features in short but useful program Object Oriented Ruby - new examples Constants in Ruby Variable scope - what is it, and how does it Ruby? Ruby to access web services This article Variable types in Ruby Ruby - Totally Topical R108 - More Classes and Objects Testing your new class - first steps with cucumber Build up classes into applications sharing data types in Ruby Where does Ruby load modules from, and how to load from current directory Changing what operators do on objects - a comparison across different programming languages Standard methods available on all objects in Ruby Private, Protected, Public in Ruby. What about interfaces and abstract classes in Ruby? Why you should use objects even for short data manipulation programs in Ruby Ruby - a training example that puts many language elements together to demonstrate the whole Ruby training - some fresh examples for string handling applications Changing a class later on - Ruby Private and Public - and things between Ruby - examples of regular expressions, inheritance and polymorphism What is a factory method and why use one? - Example in Ruby The Multiple Inheritance Conundrum, interfaces and mixins Object Oriented Ruby - new examples Direct access to object variable (attributes) in Ruby Defining a static method - Java, Python and Ruby Tips for writing a test program (Ruby / Python / Java) Ruby objects - a primer Ruby - is_a? v instance_of? - what is the difference? Object Orientation in Ruby - intermediate examples This article What are factory and singleton classes? Think about your design even if you don't use full UML MTBF of coffee machines R106 - Input and Output in Ruby Expect with Ruby - a training example to get you started Significant work - beyond helloworld in Ruby Searching through all the files in or below a directory - Ruby, Tcl, Perl Formatting your output - options available in Ruby Exclamation marks and question marks on ruby method names Ruby collections and strings - some new examples Neatly formatting results into a table Opening and reading files - the ruby fundamentals Ruby Programming Course - Saturday and Sunday This article R104 - Control Structures Alternating valuses / flip-flop / toggle - example in Ruby Where does Ruby load modules from, and how to load from current directory Separating your code for easier testing, understanding and re-use; example in Ruby Finding sum, minimum, maximum and average in Python (and Ruby) Conditionals, loops and methods in Ruby - a primer with simple examples Learning to program - Loop statements such as while Learning to Program - the conditional statement (if) Muttable v immutable and implications - Ruby Finding the total, average, minimum and maximum in a program Ruby v Perl - a comparison example Assigning values to variables within other statements - Ruby Does a for loop evaluate its end condition once, or on every iteration? Multiple inputs, multiple out, ruby functions Is this number between? Does this list include? - Ruby How a for loop works Java, Perl and other languages Returning multiple values from a function call in various languages - a comparison Ruby training - some fresh examples for string handling applications Splitting data reading code from data processing code - Ruby Why do I need brackets in Ruby ... or Perl, Python, C or Java Alternative loops and conditionals in Ruby and Perl For loop - checked once, or evety time? Ruby v Perl comparison and contrast Passing code to procedures and yield in Ruby A short form of if ... then ... else Learning to program in Ruby - examples of the programming basics Ruby, Perl, Linux, MySQL - some training notes Ruby to access web services Ruby Programming Course - Saturday and Sunday What to do with a huge crop of apples Clean code, jump free (Example in Lua) Saying NOT in Perl, PHP, Python, Lua ... This article Ruby, C, Java and more - getting out of loops for loop - how it works (Perl, PHP, Java, C, etc) A better alternative to cutting and pasting code Ruby's case - no break Equality in Ruby - == eql? and equal? Breaking a loop - Ruby and other languages 1st, 2nd, 3rd revisited in Ruby