# Re: Range#size

**URL:** <https://www.ruby-forum.com/t/re-range-size/93899>\
**Category:** Ruby\
**Created:** [April 13, 2006, 3:46pm UTC](https://www.ruby-forum.com/t/re-range-size/93899 "2006-04-13T15:46:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![KroegerS\_Simon\_Sext](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/57b2e6/32.png) [@KroegerS\_Simon\_Sext](https://www.ruby-forum.com/u/KroegerS_Simon_Sext)\
**Post date:** [April 13, 2006, 3:46pm UTC](https://www.ruby-forum.com/t/re-range-size/93899/1 "2006-04-13T15:46:53Z")

</div>

> > does anyone object to adding the method :size to class Range?
> > 
> > > def size; max - min + 1 end  
> > > end  
> > > =\> nil
> > 
> > > (“AA”…“BB”).size  
> > > NoMethodError: undefined method `-' for "BB":String from (irb):2:in`size’  
> > > from (irb):4  
> > > from :0
> 
> James Edward G. II

Well, that’s slow but could…

class Range  
def size  
inject(0){|s, dummy| s + 1}  
end  
end

…be a solution?

cheers

Simon
