From: Kenichi Kamiya Date: 2012-01-18T04:35:30+09:00 Subject: Re: Parsing log with date time entry Sorry, I have no skills for C programming. But, I guess the causes from below codes by only my intuition. # https://github.com/ruby/ruby/blob/trunk/range.c # ----------------------------------------------------------------------------- static int discrete_object_p(VALUE obj) { if (rb_obj_is_kind_of(obj, rb_cTime)) return FALSE; /* until Time#succ removed */ return rb_respond_to(obj, id_succ); } # ----------------------------------------------------------------------------- static VALUE range_include(VALUE range, VALUE val) { VALUE beg = RANGE_BEG(range); VALUE end = RANGE_END(range); int nv = FIXNUM_P(beg) || FIXNUM_P(end) || rb_obj_is_kind_of(beg, rb_cNumeric) || rb_obj_is_kind_of(end, rb_cNumeric); # ----------------------------------------------------------------------------- It looks specific rules for Time and Numeric. 2012/1/18 Peter Vandenabeele : > 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