O'Reilly logo

Ruby by Example by Kevin C. Baird

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

#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> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required