Peter Blair

Ruby and class methods

I’m just starting to learn to programme in Ruby, and wanted to play with some class methods to create a nice looking and expressive syntax.


drink = Coffee.with :milk, :cream, :sugar

When run:

$ ./coffee.rb
Creating coffee..
with Milk
with Cream
with Sugar
Cost of coffee: 2.6


Categorised as: Programming


Comments are closed.

Get Adobe Flash playerPlugin by wpburn.com wordpress themes