Extending nil methods

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 ; 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? :slight_smile:

  • reynard

hmm is google group broken? my post never seems to get through. did
get this message?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs