mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	[DOC] {Array,MatchData}#values_at understand ranges [ci skip]
This commit is contained in:
		
							parent
							
								
									93ebfed0a9
								
							
						
					
					
						commit
						947d93b715
					
				
					 2 changed files with 4 additions and 1 deletions
				
			
		
							
								
								
									
										4
									
								
								array.c
									
										
									
									
									
								
							
							
						
						
									
										4
									
								
								array.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -3728,15 +3728,17 @@ append_values_at_single(VALUE result, VALUE ary, long olen, VALUE idx)
 | 
			
		|||
 *    array.values_at(*indexes) -> new_array
 | 
			
		||||
 *
 | 
			
		||||
 *  Returns a new \Array whose elements are the elements
 | 
			
		||||
 *  of +self+ at the given \Integer +indexes+.
 | 
			
		||||
 *  of +self+ at the given \Integer or \Range +indexes+.
 | 
			
		||||
 *
 | 
			
		||||
 *  For each positive +index+, returns the element at offset +index+:
 | 
			
		||||
 *    a = [:foo, 'bar', 2]
 | 
			
		||||
 *    a.values_at(0, 2) # => [:foo, 2]
 | 
			
		||||
 *    a.values_at(0..1) # => [:foo, "bar"]
 | 
			
		||||
 *
 | 
			
		||||
 *  The given +indexes+ may be in any order, and may repeat:
 | 
			
		||||
 *    a = [:foo, 'bar', 2]
 | 
			
		||||
 *    a.values_at(2, 0, 1, 0, 2) # => [2, :foo, "bar", :foo, 2]
 | 
			
		||||
 *    a.values_at(1, 0..2) # => ["bar", :foo, "bar", 2]
 | 
			
		||||
 *
 | 
			
		||||
 *  Assigns +nil+ for an +index+ that is too large:
 | 
			
		||||
 *    a = [:foo, 'bar', 2]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										1
									
								
								re.c
									
										
									
									
									
								
							
							
						
						
									
										1
									
								
								re.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -2077,6 +2077,7 @@ match_aref(int argc, VALUE *argv, VALUE match)
 | 
			
		|||
 *     m = /(.)(.)(\d+)(\d)/.match("THX1138: The Movie")
 | 
			
		||||
 *     m.to_a               #=> ["HX1138", "H", "X", "113", "8"]
 | 
			
		||||
 *     m.values_at(0, 2, -2)   #=> ["HX1138", "X", "113"]
 | 
			
		||||
 *     m.values_at(1..2, -1)   #=> ["H", "X", "8"]
 | 
			
		||||
 *
 | 
			
		||||
 *     m = /(?<a>\d+) *(?<op>[+\-*\/]) *(?<b>\d+)/.match("1 + 2")
 | 
			
		||||
 *     m.to_a               #=> ["1 + 2", "1", "+", "2"]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue