Re: Range#size

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:insize’
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

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