# Extending nil methods

**URL:** <https://www.ruby-forum.com/t/extending-nil-methods/109802>\
**Category:** Rails\
**Created:** [July 19, 2007, 6:34am UTC](https://www.ruby-forum.com/t/extending-nil-methods/109802 "2007-07-19T06:34:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Reynard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/6bbea6/32.png) [@Reynard](https://www.ruby-forum.com/u/Reynard)\
**Post date:** [July 19, 2007, 6:34am UTC](https://www.ruby-forum.com/t/extending-nil-methods/109802/1 "2007-07-19T06:34:28Z")

</div>

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  
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

---

<div class="post-metadata">

**Author:** ![Reynard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/6bbea6/32.png) [@Reynard](https://www.ruby-forum.com/u/Reynard)\
**Post date:** [September 25, 2007, 11:10pm UTC](https://www.ruby-forum.com/t/extending-nil-methods/109802/2 "2007-09-25T23:10:29Z")

</div>

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