Training, Open Source computer languages

PerlPHPPythonMySQLhttpd / TomcatTclRubyJavaC and C++LinuxCSS

Search our site for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
1st, 2nd, 3rd revisited in Ruby
I've been updating some of my Ruby examples today (as one does on a Saturday!) and I thought back to the post I made yesteday concerning 1st, 2nd, 3rd, etc in Python.

Ruby has a case statement, even though Ruby is a bit of a cross between Python and Perl, neither of which supports the structure. Historically, it's been difficult for language authors to come up with a really good multiple way switch but actually the Ruby one is rather smart. Compare this Ruby to the Python code I wrote yesterday:

case value
when 1,21,31
  suffix = "st"
when 2,22
  suffix = "nd"
when 3,23
  suffix = "rd"
else
  suffix = "th"
end

puts "It is the #{value}#{suffix} of the month"


Oh - I'm revising this for the public Ruby course that's running on 14th and 15th December ... places still available at £550.00 (first delegate) and £440.00 (second and subsequent delegate on same running of the course / same order. Maximum of 7 delegates taken, and just 3 rooms available as I write, Hurry hurry hurry!!
(written 2006-12-02 17:15:03)

 
Associated topics are indexed under
R104 - Ruby - Control Structures

Back to
It's the 1st, not the 1nd 1rd or 1th.
Previous and next
or
Horse's mouth home
Forward to
Products that our customers want more of

Some other Articles
Practical polymorphism in action
George Hotel and Well House Manor, Melksham
Breaking a loop - Ruby and other languages
Products that our customers want more of
1st, 2nd, 3rd revisited in Ruby
It's the 1st, not the 1nd 1rd or 1th.
Plain Ole nice pictures
Improving the historic town of Melksham
Python security - trouble with input
Python collections - mutable and imutable
1694 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 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).

© WELL HOUSE CONSULTANTS LTD., 2008: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 707126 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho