Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
Python and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Lua, etc
 
Clear, concise examples - Ruby classes and objects.

Finding clear, concise examples of how to perform a simple programming task can be surprisingly difficult. "I just want a [Rails] model that doesn't actually use a database table" was an example yesterday. Such shouldn't be difficult, but authors tend to write a simple example and then decide "While I'm at it, I could show X as well" and "I should include Y because it's a good alternative" and "I could be critisized for not covering Z so I'll cover it" ... and the result is an example which doesn't actually fulfill the original requirement of being clear and concise.

I fall into the same trap sometimes ...

On Thursday, I wrote an example to show how a class is defined, how an object is created within that class, and how the object is accessed. Good. And I then extended the example to show:
• how the class can be loaded from a separate file
• how we can use an array of objects
• how we can use a factory method to manufacture objects of a given type
• how we can include class variables and methods as well as object variables
• how we can extend the class to create other similar classes without repeating code

Fortunately, I saved a copy of my original (straightforward) example so that I can re-use it as a first "This is how I create and use an object in Ruby" example - it's [here].

The extended copy (if you would like a comparison, and to move on to all the exciting stuff) is [here], with the class code broken out into a separate file [here].

Examples like this from our ... Ruby Courses.
(written 2013-02-17)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
G504 - Well House Consultants - Writing Notes
  [4031] Showing what programming errors look like - web site pitfall - (2013-03-06)
  [3152] Jargon busting - (2011-01-30)
  [2828] Sharing our programs - easy. Sharing our data - harder. - (2010-06-26)
  [2812] What is Perl? - (2010-06-15)
  [2481] Sample code with errors in it on our web site - (2009-10-29)
  [2414] Hello World - a good traditional start to a Java course - (2009-09-22)
  [2192] Copy writing - allowing for the cut - (2009-05-21)
  [2010] How long should a training module be? - (2009-01-27)
  [1950] Copyright of Training Notes and Web Site - (2008-12-18)
  [982] Notes from the white board - (2006-12-14)
  [979] Empty seats, Nodding Donkeys and buses - (2006-12-11)
  [797] Writing up new C / C++ notes. - (2006-07-09)
  [407] Theft of training material - (2005-08-09)
  [398] Training course material - why we write our own - (2005-07-30)
  [394] A year on - should we offer certified PHP courses - (2005-07-28)
  [9] Study room - the Oxford train - (2004-08-10)
  [7] Writing on a Sunday - (2004-08-08)
  [4] Seeing the wood for the trees. - (2004-08-06)

R102 - Hello Ruby Objects
  [4673] Separating detailed data code from the main application - Ruby example - (2016-05-16)
  [4581] Thin application, thick objects - keep you main code simple. Example in Ruby - (2015-11-21)
  [4580] Easy example - data record to object and object to data record mapping in Ruby - (2015-11-21)
  [4369] Ruby - the second rung of learning the language - (2014-12-28)
  [2603] Ruby objects - a primer - (2010-01-29)
  [2287] Learning to program in Ruby - examples of the programming basics - (2009-07-15)

R105 - Ruby - Classes and Objects
  [4502] Reading and parsing a JSON object in Ruby - (2015-06-01)
  [3421] Ruby off the Rails? - (2011-09-06)
  [2651] Calculation within objects - early, last minute, or cached? - (2010-02-26)
  [2616] Defining a static method - Java, Python and Ruby - (2010-02-01)
  [2609] Scope of variables - important to Ruby on Rails - (2010-01-31)
  [2292] Object Orientation in Ruby - intermediate examples - (2009-07-16)
  [1925] Introduction to Object Oriented Programming - (2008-12-06)
  [983] Blessing in Perl / Member variable in Ruby - (2006-12-14)


Back to
Reading and checking user inputs - first lessons - Ruby
Previous and next
or
Horse's mouth home
Forward to
Really Simple Rails
Some other Articles
Web Frameworks - nested templates
A course is not just for a year - its for a career
From Salford
Really Simple Rails
Clear, concise examples - Ruby classes and objects.
Reading and checking user inputs - first lessons - Ruby
Which database should I use? MySQL v SQLite
Ruby / SQLite3 example program, showing JOIN v LEFT JOIN
New guest ... becoming returning guest
Annual Accounts - a big job for a small business
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2019: 404 The Spa • Melksham, Wiltshire • United Kingdom • SN12 6QL
PH: 01225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/4009_Cle ... ects-.html • PAGE BUILT: Sat May 27 16:49:10 2017 • BUILD SYSTEM: WomanWithCat