Patrick Hurley
3/24/2005 12:38:00 AM
Oh btw, if you keep at it the DwemthysArray gets a little nasty
sending messages to Nil and nil does not seem to appreciate the extra
attention. So a minor change like below seems to help.
Thanks as always for the enjoyable read, yours is one of the more
interesting ways to introduce people to Ruby.
Patrick
*** dwemthy-orig.rb Wed Mar 23 14:33:52 2005
--- dwemthy.rb Wed Mar 23 15:20:07 2005
***************
*** 64,76 ****
alias _inspect inspect
def inspect; "#<#{ self.class }#{ _inspect }>"; end
def method_missing( meth, *args )
answer = first.send( meth, *args )
! if first.life <= 0
! shift
! if empty?
! puts "[Whoa. You decimated Dwemthy's Array!]"
! else
! puts "[Get ready. #{ first.class } has emerged.]"
end
end
answer || 0
--- 64,80 ----
alias _inspect inspect
def inspect; "#<#{ self.class }#{ _inspect }>"; end
def method_missing( meth, *args )
+ if empty?
+ puts "[Quit flogging my dead monsters!]"
+ else
answer = first.send( meth, *args )
! if first.life <= 0
! shift
! if empty?
! puts "[Whoa. You decimated Dwemthy's Array!]"
! else
! puts "[Get ready. #{ first.class } has emerged.]"
! end
end
end
answer || 0