Forum: Ruby on Rails extending nil methods

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Be2b66038e24ecc43fb890ab9ce6c635?d=identicon&s=25 Reynard (Guest)
on 2007-07-19 06:34
(Received via mailing list)
it seems my previous post didn't get through for some reason, so sorry
if this is duplicated.

has anyone done something like this?

class NilClass
  def empty?; true; end
  def strip; nil; end
  def [](s); nil; end

so you can do this without throwing exception
if !params[:s].empty?
if !params[:s][:e].strip.empty?

as opposed to:
if params[:s] && !params[:s].empty?
if params[:s] && params[:s][:e] && !params[:s][:e].strip.empty?

I'm just wondering is there negative effects of doing this? if not
then shouldn't we be doing this. it makes your code look a lot nicer
doesn't it? :)

- reynard
Be2b66038e24ecc43fb890ab9ce6c635?d=identicon&s=25 Reynard Hilman (Guest)
on 2007-09-25 23:10
(Received via mailing list)
hmm is google group broken? my post never seems to get through. did
get this message?
This topic is locked and can not be replied to.