From: James Edward Gray II Date: 2006-11-15T01:42:12+09:00 Subject: Re: Immediate, Immutable, Singleton etc On Nov 14, 2006, at 10:26 AM, Ilan Berci wrote: > Singleton: This is a gof pattern meanting that you can have exactly > one > instance of an object. This term is often used with Ruby in a different manner. In Ruby a "singleton method" is a method added to an individual object: >> normal = (1..5).to_a => [1, 2, 3, 4, 5] >> special = normal.dup => [1, 2, 3, 4, 5] >> class << special >> def shuffle! >> replace(sort_by { rand }) >> end >> end => nil >> special.shuffle! => [5, 1, 4, 2, 3] >> normal.shuffle! NoMethodError: undefined method `shuffle!' for [1, 2, 3, 4, 5]:Array from (irb):10 Ruby does also have an implementation of the GoF pattern though, in the singleton standard library. James Edward Gray II