#18 Currency Conversion, Basic (currency_converter1.rb)

I mentioned earlier that the commify method needs to vary based on how each country treats the notation of numbers. The area where this issue comes up most often is with currency, of course. The actual conversion process consists of relatively straightforward math, but we’ll use this script as a vehicle to set the stage for two important concepts introduced in our next script—notably the representation of data with either XML (eXtensible Markup Language, http://www.w3c.org/xml) or YAML (YAML Ain’t Markup Language, http://www.yaml.org). We’ll explore both XML and YAML further in the next script, but for now, let’s try out our current script in irb with irb -r currency_converter.rb.

 irb(main):001:0> ...

Get Ruby by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.