Sunday, September 2, 2007

Add custom operators in Ruby

Jay Phillips developed the 'superators' gem, which enables the use of custom operators in Ruby. for example.

  1. require 'rubygems'  
  2. require 'superators'  
  3.   
  4. class Array  
  5.   superator "<---" do |operand|  
  6.     self << operand.reverse  
  7.   end  
  8. end  
  9.   
  10. ["jay"] <--- "spillihp"  

No comments:

Post a Comment

Tell me what you think