Link Details

Link 38587 thumbnail
User 204894 avatar

By arikthered
via coderoshi.blogspot.com
Published: Sep 02 2007 / 17:43

Nil in Ruby represents "nothing". But it is not nothing - it is a real object. Don't be afraid to take charge and bend nil to your bidding.
  • 12
  • 0
  • 1916
  • 583

Comments

Add your comment
User 207602 avatar

Jim Wilson replied ago:

0 votes Vote down Vote up Reply

Very clever - avoiding initializers by defining new methods on nil.

I might even suggest the following additions:

def nil.push(o); [o]; end
def nil.<<(o); o; end

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.