On Mon, Jun 19, 2006 at 05:04:32PM +1000, Andre Pang wrote:
> Does Ruby permit you to add new methods to a existing classes?   

Yes, you just reopen the class and add/override your method.  For example, a
nice randomisation method for arrays:

class Array
  def randomise
    sort_by { rand }
  end
  
  def randomise!
    self = randomise
  end
end

(Takes unfair advantage of Ruby's practice of defaulting a call without an
object to sending to the current object)

- Matt
_______________________________________________
coders mailing list
coders@slug.org.au
http://lists.slug.org.au/listinfo/coders

Reply via email to