|
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
Some other Articles
Practical polymorphism in actionGeorge Hotel and Well House Manor, MelkshamBreaking a loop - Ruby and other languagesProducts that our customers want more of1st, 2nd, 3rd revisited in RubyIt's the 1st, not the 1nd 1rd or 1th.Plain Ole nice picturesImproving the historic town of MelkshamPython security - trouble with inputPython collections - mutable and imutable
|
2259 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 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).
|
|