nemorathwald: (thoughts)
nemorathwald ([personal profile] nemorathwald) wrote2009-02-01 09:14 pm

Dalmation Plantation Concatenation Notation

I and [livejournal.com profile] le_bebna_kamni are sitting in Espresso Royale practicing programming in Ruby. We did the same exercise for making singular and plural sentences. When I looked at the way she did it in her version, I didn't recognize what the hash sign followed by curly braces is supposed to do. She explained it for a while. I summarized.

"So it's a concatenation notation."

"Yeah."

"For a dalmation plantation."

"It'll be a sensation!"

Breaking out into song
A concatenation notation,
Where our population can roam
If this new location
Our whole aggregation
Will love our plantation home!
Then she made new code to demonstrate how it works in terms I would understand:

#!/usr/bin/ruby

def pluralize(unit, quantity)
  if quantity == 1 then
      return "#{quantity} #{unit}"
  else
      return "#{quantity} #{unit}s"
  end
end

print "Concatenation for the Dalmation Plantation: ", \
  pluralize("Dalmation", 101),"\n"
Output:
Concatenation for the Dalmation Plantation: 101 Dalmations

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting