From: Peter Vandenabeele Date: 2012-01-18T03:56:23+09:00 Subject: Re: Parsing log with date time entry --00235446fcd40b708704b6bde38f Content-Type: text/plain; charset=UTF-8 On Tue, Jan 17, 2012 at 7:44 PM, Kenichi Kamiya wrote: > Range#=== , need #succ method in Ruby1.9.3 > under only #<=>, use Range#cover? > Thank you. For Time class, I could get it to work. This will simplify the code for the OP. $ irb 1.9.3-p0 :001 > t2 = Time.now => 2012-01-17 19:47:19 0100 1.9.3-p0 :002 > t1 = t2 - 900 => 2012-01-17 19:32:19 0100 1.9.3-p0 :003 > time_range = t1..t2 => 2012-01-17 19:32:19 0100..2012-01-17 19:47:19 0100 1.9.3-p0 :004 > t3 = Time.now - 300 => 2012-01-17 19:42:41 0100 1.9.3-p0 :006 > time_range === t3 TypeError: can't iterate from Time from (irb):6:in `each' from (irb):6:in `include?' from (irb):6:in `include?' from (irb):6:in `===' from (irb):6 from /home/peterv/.rvm/rubies/ruby-1.9.3-p0/bin/irb:16:in `
' 1.9.3-p0 :007 > time_range.cover? t3 => true # :-) 1.9.3-p0 :008 > time_range.cover? Time.now => false # :-) However, for Float the === operator seems to work, _without_ Float#succ 1.9.3-p0 :009 > f1 = 13.6 => 13.6 1.9.3-p0 :010 > f2 = 18.6 => 18.6 1.9.3-p0 :011 > float_range = f1..f2 => 13.6..18.6 1.9.3-p0 :012 > float_range === 15.5 => true 1.9.3-p0 :013 > f1.succ NoMethodError: undefined method `succ' for 13.6:Float from (irb):13 from /home/peterv/.rvm/rubies/ruby-1.9.3-p0/bin/irb:16:in `
' 1.9.3-p0 :014 > float_range.cover? 15.5 => true So, maybe the behavior could be made similar? I suggest that `Range#=== arg` falls back to `Range#cover? arg` uniformily if `arg.respond_to?(:succ)` is false (and probably other conditions). Thanks again, Peter --00235446fcd40b708704b6bde38f--