mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	* range.c (range_cover): new method Range#cover? added. the
method name might be changed. thanks to takano32 at http://www.rubyist.net/~matz/20051210.html#c08 for name suggestion. [ruby-talk:167182] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9674 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									4d467a0865
								
							
						
					
					
						commit
						81be039884
					
				
					 2 changed files with 40 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -1,3 +1,10 @@
 | 
			
		|||
Mon Dec 12 09:58:09 2005  Yukihiro Matsumoto  <matz@ruby-lang.org>
 | 
			
		||||
 | 
			
		||||
	* range.c (range_cover): new method Range#cover? added.  the
 | 
			
		||||
	  method name might be changed.  thanks to takano32 at
 | 
			
		||||
	  http://www.rubyist.net/~matz/20051210.html#c08 for name
 | 
			
		||||
	  suggestion.  [ruby-talk:167182]
 | 
			
		||||
 | 
			
		||||
Mon Dec 12 00:33:56 2005  Yukihiro Matsumoto  <matz@ruby-lang.org>
 | 
			
		||||
 | 
			
		||||
	* ext/digest/digest.c (rb_digest_base_s_digest): add volatile to
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										33
									
								
								range.c
									
										
									
									
									
								
							
							
						
						
									
										33
									
								
								range.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -641,6 +641,38 @@ range_include(VALUE range, VALUE val)
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 *  call-seq:
 | 
			
		||||
 *     rng.cover?(val)  =>  true or false
 | 
			
		||||
 *  
 | 
			
		||||
 *  Returns <code>true</code> if <i>obj</i> is between beg and end,
 | 
			
		||||
 *  i.e <code>beg <= obj <= end</code> (or <i>end</i> exclusive when
 | 
			
		||||
 *  <code>exclude_end?</code> is true).
 | 
			
		||||
 *     
 | 
			
		||||
 *     ("a".."z").cover?("c")    #=> true
 | 
			
		||||
 *     ("a".."z").cover?("5")    #=> false
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
static VALUE
 | 
			
		||||
range_cover(range, val)
 | 
			
		||||
    VALUE range, val;
 | 
			
		||||
{
 | 
			
		||||
    VALUE beg, end;
 | 
			
		||||
 | 
			
		||||
    beg = rb_ivar_get(range, id_beg);
 | 
			
		||||
    end = rb_ivar_get(range, id_end);
 | 
			
		||||
    if (r_le(beg, val)) {
 | 
			
		||||
	if (EXCL(range)) {
 | 
			
		||||
	    if (r_lt(val, end)) return Qtrue;
 | 
			
		||||
	}
 | 
			
		||||
	else {
 | 
			
		||||
	    if (r_le(val, end)) return Qtrue;
 | 
			
		||||
	}
 | 
			
		||||
    }
 | 
			
		||||
    return Qfalse;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*  A <code>Range</code> represents an interval---a set of values with a
 | 
			
		||||
 *  start and an end. Ranges may be constructed using the
 | 
			
		||||
 *  <em>s</em><code>..</code><em>e</em> and
 | 
			
		||||
| 
						 | 
				
			
			@ -718,6 +750,7 @@ Init_Range(void)
 | 
			
		|||
 | 
			
		||||
    rb_define_method(rb_cRange, "member?", range_include, 1);
 | 
			
		||||
    rb_define_method(rb_cRange, "include?", range_include, 1);
 | 
			
		||||
    rb_define_method(rb_cRange, "cover?", range_cover, 1);
 | 
			
		||||
 | 
			
		||||
    id_cmp = rb_intern("<=>");
 | 
			
		||||
    id_succ = rb_intern("succ");
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue