Main Content
Object Oriented Ruby - new examples Archive - Originally posted on "The Horse's Mouth" - 2010-02-03 23:01:43 - Graham Ellis
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 examples:
[link] - a straightforward example of a class definintion, no inheritance, nothing fancy (thout it does have an attribute accessor)
[link] - a demonstration that shows inheritance, embedding of classes within a module, static variable and methods, operator overloading, a singleton method and much more. There are plenty of comments in the source code of this example.
[link] - showing the difference between object and class (dymanic and static) variables.
The following new examples have also been added in other areas:
[link] - command line parameters to a Ruby program
[link] - BEGIN and END blocks, and autosplit
[link] - a comparison of symbols and strings in Ruby
[link] Commenting a regular expression 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 This article Constants in Ruby Variable scope - what is it, and how does it Ruby? Ruby to access web services Some Ruby programming examples from our course Variable types in Ruby Ruby - Totally Topical R109 - Strings and Regular Expressions Clarrissa-Marybelle - too long to really fit? Regular Expressions for the petrified - in Ruby Global Regular Expression matching in Ruby (using scan) Ruby - standard operators are overloaded. Perl - they are not Ruby - a teaching example showing many of the language features in short but useful program Matching regular expressions, and substitutions, in Ruby Divide 10000 by 17. Do you get 588.235294117647, 588.24 or 588? - Ruby and PHP Ruby - examples of regular expressions, inheritance and polymorphism This article Ruby collections and strings - some new examples Neatly formatting results into a table Search and replace in Ruby - Ruby Regular Expressions The dog is not in trouble Regular Expressions in Ruby Ruby to access web services Ruby Programming Course - Saturday and Sunday What are exceptions - Python based answer String interpretation in Ruby Regular expressions made easy - building from components Regular Express Primer Ruby v Perl - interpollating variables puts - opposite of chomp in Ruby String duplication - x in Perl, * in Python and Ruby 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 This article 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 Some Ruby programming examples from our course What are factory and singleton classes? Think about your design even if you don't use full UML MTBF of coffee machines