manager 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/CHART.html +1270 -0
  3. data/MANUAL.html +1252 -0
  4. data/bin/manager +43 -0
  5. data/examples/array/CHART.html +1376 -0
  6. data/examples/array/MANUAL.html +1126 -0
  7. data/examples/array/spec +3438 -0
  8. data/lib/manager.rb +528 -0
  9. data/lib/manager/annotation +96 -0
  10. data/lib/manager/input +189 -0
  11. data/lib/manager/js +257 -0
  12. data/lib/manager/refine_module +142 -0
  13. data/lib/manager/refine_object_mapping +143 -0
  14. data/lib/manager/refine_test +97 -0
  15. data/lib/manager/render +1228 -0
  16. data/lib/manager/spell_check +49 -0
  17. data/lib/manager/test +404 -0
  18. data/lib/manager/test_helper +9 -0
  19. data/license +9 -0
  20. data/manager.gemspec +21 -0
  21. data/spec/alternatives_implemented.png +0 -0
  22. data/spec/alternatives_unimplemented.png +0 -0
  23. data/spec/annotations.png +0 -0
  24. data/spec/benchmark_test.png +0 -0
  25. data/spec/citation.png +0 -0
  26. data/spec/code_block.png +0 -0
  27. data/spec/context_module.png +0 -0
  28. data/spec/documentation +1289 -0
  29. data/spec/external_link.png +0 -0
  30. data/spec/image.png +0 -0
  31. data/spec/list.png +0 -0
  32. data/spec/long.png +0 -0
  33. data/spec/main_and_object.png +0 -0
  34. data/spec/markup.png +0 -0
  35. data/spec/module_diagram.png +0 -0
  36. data/spec/navigation.png +0 -0
  37. data/spec/nested_section_headers.png +0 -0
  38. data/spec/ruby.png +0 -0
  39. data/spec/setup_teardown.png +0 -0
  40. data/spec/short.png +0 -0
  41. data/spec/signature.png +0 -0
  42. data/spec/spec +76 -0
  43. data/spec/spec_example.png +0 -0
  44. data/spec/table.png +0 -0
  45. data/spec/test_header.png +0 -0
  46. data/spec/test_non_unit_spec +184 -0
  47. data/spec/test_program +71 -0
  48. data/spec/test_unit_spec +790 -0
  49. data/spec/tutorial_1.png +0 -0
  50. data/spec/tutorial_2.png +0 -0
  51. data/spec/tutorial_3.png +0 -0
  52. data/spec/tutorial_4.png +0 -0
  53. data/spec/tutorial_5.png +0 -0
  54. data/spec/tutorial_6.png +0 -0
  55. data/spec/tutorial_7.png +0 -0
  56. data/spec/tutorial_8.png +0 -0
  57. data/spec/unambiguous_links.png +0 -0
  58. data/spec/unit_test_failure.png +0 -0
  59. data/spec/unit_test_raise.png +0 -0
  60. data/spec/unit_test_receiver.png +0 -0
  61. data/spec/unit_test_succeed.png +0 -0
  62. data/spec/unit_test_success.png +0 -0
  63. data/spec/unit_test_throw.png +0 -0
  64. data/spec/valid_heading.png +0 -0
  65. data/spec/with_expr.png +0 -0
  66. data/spec/without_expr.png +0 -0
  67. data/theme/2016a.css +670 -0
  68. data/theme/coderay_github.css +132 -0
  69. metadata +140 -11
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Copyright (c) 2016 sawa
5
+
6
+ require "manager"
7
+
8
+ command_options = {debug: false}
9
+ ARGV.map!(&:+@)
10
+ while ARGV.first.sub!(/\A--?/, "")
11
+ k, v = ARGV.shift.split("=")
12
+ k, v = k.tr("-", "_").to_sym, v || true
13
+ case k
14
+ when :theme_list
15
+ Dir.glob("#{__dir__}/../theme/*").each do
16
+ |f|
17
+ File.new(f).each.first[%r[/\*\s*(.+?)\s*\*/]]
18
+ puts "#{File.basename(f)}#{" [#$1]" if $1}"
19
+ end
20
+ exit
21
+ when :highlight_list
22
+ puts CodeRay::Scanners.list
23
+ exit
24
+ when :spell_check_list
25
+ puts Manager::Spellcheck.list
26
+ exit
27
+ when :spell_check_filter
28
+ language = ARGV.shift
29
+ begin
30
+ a = Manager::Spellcheck.filter(language, ARGV)
31
+ puts "The following words are not in the dictionary `#{language}`: "
32
+ a.each{|w| puts w}
33
+ rescue => e
34
+ puts e.message
35
+ end
36
+ exit
37
+ when :bdir, :odir, :user, :dev, :theme, :highlight, :debug, :spell_check, :case_sensitive, :case_insensitive, :timeout, :title, :coverage
38
+ command_options.store(k, v)
39
+ else abort "Invalid option #{k}"
40
+ end
41
+ end
42
+ abort "Spec file not given" if ARGV.empty?
43
+ Manager.new(File.expand_path(ARGV.shift), **command_options)
@@ -0,0 +1,1376 @@
1
+ <html><head><meta charset="UTF-8" /><style>/*Author:sawa.The default design */*{box-sizing:border-box;-webkit-user-select:text;-khtml-user-select:text;-moz-user-select:text;-ms-user-select:text;user-select:text;}body,table{font-family:sans-serif;font-size:12px;}body{margin:0;display:flex;flex-wrap:nowrap;align-items:stretch;flex-direction:row;height:100%;text-align:justify;text-rendering:optimizelegibility;color:hsl(100,0%,30%);background-color:hsl(0,0%,100%);word-break:normal;}#top,#top-title{display:flex;flex-wrap:wrap;align-items:center;justify-content:center;font-size:18px;}#top *{-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;}#top,#user #top-title{padding:2;background-color:hsl(0,0%,97%);color:hsl(0,0%,30%);}#dev #top-title{margin:1em;color:white;}#user #top-title,#dev #top{border-bottom:solid 6px hsl(211,85%,29%);}#top >span{margin-left:5;margin-right:5;display:inline-flex;flex-direction:row;flex-wrap:wrap;align-items:center;justify-content:center;white-space:pre;padding-top:4;padding-bottom:4;}.separator{font-size:18px;color:hsl(60,5%,72%);margin-left:0.5em;margin-right:0.5em;}#left{padding:0 20 24 40;flex-basis:480px;flex-shrink:0;display:flex;flex-wrap:nowrap;align-items:stretch;flex-direction:column;border-right:solid 1px hsl(60,5%,68%);background-color:#4F6B89;color:hsl(0,0%,100%);}#left .tablewrapper{max-height:32%;overflow-y:auto;border-top:solid 1px hsl(60,5%,85%);border-bottom:solid 1px hsl(60,5%,85%);}#left table{margin:0;width:100%;background-color:hsl(0,0%,100%);}#gemspec td:nth-child(1){white-space:nowrap;}#gemspec td:nth-child(2){word-break:break-all;}#files td:nth-child(3),#files td:nth-child(4){white-space:nowrap;}#files td:nth-child(4){text-align:right;}#right{display:flex;flex-wrap:nowrap;align-items:stretch;flex-direction:column;overflow:hidden;flex-grow:1;}#main{flex-basis:0;flex-grow:1;display:flex;flex-wrap:nowrap;align-items:stretch;flex-direction:column;overflow-y:auto;}#user #main{padding-top:12;padding-bottom:12;padding-right:240;padding-left:240;}#dev #main{padding-top:12;padding-bottom:12;padding-right:40;padding-left:20;}#main:before{position:fixed;margin-top:20px;margin-left:-20px;content:"\25B8";/*blacktriangleright */}#user #main:before{top:234;}#dev #main:before{top:300;}[onclick]:not([folded]){cursor:pointer;}[onclick][folded="true"]{cursor:s-resize;}[onclick][folded="false"]{cursor:n-resize;}table{border-collapse:collapse;margin-top:1em;margin-bottom:1em;}tr{border-color:hsl(60,27%,78%);border-style:solid;}#left tr:first-of-type{border-left-width:1px;border-right-width:1px;border-top-width:0;border-bottom-width:1px;}#left tr:last-of-type{border-left-width:1px;border-right-width:1px;border-top-width:1px;border-bottom-width:0;}#main tr,#left tr:not(:last-of-type):not(:first-of-type){border-left-width:1px;border-right-width:1px;border-top-width:1px;border-bottom-width:1px;}td{padding-left:3px;padding-right:3px;border-style:solid;border-color:hsl(60,27%,78%);border-width:1px;}figure{text-align:center;margin-left:0;margin-right:0;}figcaption{text-align:center;margin:2;}input{vertical-align:middle;}h1,h2,h3,h4{display:flex;flex-direction:row;align-items:center;white-space:pre-wrap;word-break:break-word;font-weight:normal;/*color:hsl(180,93%,6%);*/}h1{color:hsl(9,30%,15%);}h2{font-size:163%;margin-left:1em;margin-right:0.5em;color:hsl(9,30%,15%);}h3{font-size:140%;margin-left:1em;margin-right:0.5em;padding-left:1em;border-bottom:solid 1px hsl(0,0%,80%);color:hsl(9,30%,15%);}h4{font-size:120%;margin-left:1em;margin-right:0.5em;padding-left:2em;border-bottom:solid 1px hsl(0,0%,80%);font-style:oblique;color:hsl(9,30%,15%);}h5{font-size:110%;margin-left:1em;margin-right:0.5em;padding-left:3em;border-bottom:solid 1px hsl(0,0%,80%);color:hsl(9,30%,15%);}h6{font-size:100%;margin-left:1em;margin-right:0.5em;padding-left:4em;border-bottom:solid 1px hsl(0,0%,80%);color:hsl(9,30%,15%);}.module-header{/*Margin among `h2.module-header`does not collapse because of extra embedding level `.margin`.Hence margin needs to be set to half of other `h2`.*/margin-top:0.415em;margin-bottom:0.415em;}.feature:not(:first-child)[onclick]:hover{background-color:hsl(90,10%,97%);}.feature-name{font-size:110%;font-weight:bold;font-family:sans-serif;}[folded="true"]>h1,[folded="true"]>h2,[folded="true"]>h3,[folded="true"]>h4,[folded="true"]>h5,[folded="true"]>h6{box-shadow:inset 0px -21px 46px -26px hsla(0,0%,0%,0.2);}.feature-contents{padding-left:1em;}.head{font-weight:bold;font-family:sans-serif;font-size:15px;}.user-item,.dev-item{margin-top:1;margin-bottom:1;padding-left:0.5em;padding-right:0.5em;border-radius:5px;}#dev .user-item{background-color:hsl(180,20%,86%);padding-top:0.1px;padding-bottom:0.1px;}.diagram{text-align:left;margin:0.75em 2em;}.mixins{display:inline-block;margin:2 1;background-color:#c2ccd5;border:solid 1px #246a7d;color:#246a7d;padding:1 4;border-radius:2px;font-size:10.5px;}.mixins >div{width:100%;text-align:center;line-height:2.55ex;}.mixins >.baseline ~div{float:left;clear:both;}.p,li{font-family:serif;font-size:17px;}.p{margin-top:1em;margin-bottom:1em;}.CodeRay,table,figure{margin-top:1.33em;margin-bottom:1.33em;margin-left:2em;margin-right:2em;}.dev-text,table{font-family:sans-serif;font-size:13px;}.CodeRay{overflow-x:auto;}.CodeRay,code{font-size:12px;}.inline{padding:3px 4px;line-height:2.5ex;border-radius:0.4ex;white-space:pre-wrap;font-size:12px;background-color:hsl(50,35%,89%);color:hsl(0,0%,40%);word-break:break-all;}li{margin-top:5;margin-bottom:5;}.indent{padding-left:2.3em;}.hang-indent{margin-right:-2.3em;}.statistics{font-size:12px;}#current{color:black;font-weight:bold;}.navigation{display:inline-flex;flex-direction:row;align-items:center;}.mode.tag,.arrow.tag,.missing_doc.tag,.navigation .bad_doc.tag,.agenda.tag,.log.tag,.missing_test.tag,.bad_test.tag,.untestable.tag,.bug.tag,.success.tag,.benchmark.tag{display:inline-flex;flex-direction:row;align-items:center;justify-content:center;white-space:pre;height:18px;margin:2 0;padding-left:5.5;padding-right:5.5;font-family:sans-serif;font-size:10px;font-weight:500;border-radius:9px;}.unimplemented.tag,.protected.tag,.private.tag,.public.tag,.constant.tag,.singleton.tag,.instance.tag,.undocumented.tag,.hidden.tag,.misplaced.tag,.moved.tag{display:inline-flex;flex-direction:row;align-items:center;justify-content:center;white-space:pre;height:18px;margin:2 0;padding-left:5.5;padding-right:5.5;font-family:sans-serif;font-size:10px;font-weight:500;border-radius:2px;}.tag.mode,.tag.arrow{color:hsl(9,69%,16%);vertical-align:middle;line-height:100%;font-size:12px;}.constant{color:#DB7551;}.constant.tag{background-color:#DB7551;color:white;}.singleton{color:#68894F;}.singleton.tag{background-color:#68894F;color:white;}.instance{color:#4F6589;}.instance.tag{background-color:#4F6589;color:white;}.public{color:#090705;}.public.tag{background-color:#CCBBA7;border:solid 1px;}.private{color:#090705;}.private.tag{background-color:#9B7C59;border:solid 1px;}.protected{color:#D6AF86;}.protected.tag{background-color:#47160D;border:solid 1px;}.hidden,.moved{color:gray;}.hidden.tag,.moved.tag{background-color:white;color:#878787;border:solid 1px;}.agenda{color:#878787;}.agenda.tag{background-color:#878787;color:white;}.log{color:#878787;}.log.tag{background-color:white;color:#878787;border:solid 1px;}.undocumented,.misplaced,.missing_doc,.bad_doc,.missing_test,.bad_test{color:#F79833;}.navigation .bad_doc{font-weight:inherit;text-decoration:inherit;}.anchor .bad_doc{font-weight:bold;border-bottom:dotted 2px;}.undocumented.tag,.misplaced.tag,.missing_doc.tag,.navigation .bad_doc.tag,.missing_test.tag,.bad_test.tag{background-color:#F79833;color:white;}.untestable{color:hsl(54,43%,38%);}.untestable.tag{background-color:hsl(54,43%,38%);color:white;}.unimplemented,.bug{color:hsl(0,80%,50%);}.unimplemented.tag,.bug.tag{background-color:hsl(0,80%,50%);color:white;}.success{color:#00a15a;}.success.tag{background-color:#00a15a;color:white;}.backtrace col:nth-child(1){width:100%;}.backtrace td:nth-child(2)>code{white-space:nowrap;}.benchmark{color:hsl(263,43%,38%);}.benchmark.tag{background-color:hsl(263,43%,38%);color:white;}.barcharts{border-collapse:separate;border-spacing:3 0;}.barcharts col:nth-child(2){width:100%;}.barcharts td:nth-child(1)>code{float:right;font-size:73%;white-space:nowrap;}.barcharts td:nth-child(2){padding:3 0;background-color:hsl(250,7%,92%);}caption{margin:4;}.barchart{display:flex;flex-wrap:nowrap;align-items:stretch;flex-direction:row;height:21px;}.barchart .fill{padding:0 6;background-color:hsl(240,40%,50%);min-width:1;color:hsl(0,0%,63%);font-family:sans-serif;font-size:75%;text-align:right;white-space:nowrap;overflow:visible;line-height:21px;}.barchart .minedge{background-color:hsl(0,50%,50%);border-style:solid;border-left-width:0;border-right-width:0;border-top-width:5px;border-bottom-width:5px;border-color:hsl(240,40%,50%);width:1px;}.barchart .maxedge{background-color:hsl(0,50%,50%);border-style:solid;border-left-width:0;border-right-width:0;border-top-width:5px;border-bottom-width:5px;border-color:hsl(250,7%,92%);width:1px;}.barchart .min{background-color:hsl(0,50%,50%);border-style:solid;border-left-width:0;border-right-width:0;border-top-width:10px;border-bottom-width:10px;border-color:hsl(240,40%,50%);}.barchart .max{background-color:hsl(0,50%,50%);border-style:solid;border-left-width:0;border-right-width:0;border-top-width:10px;border-bottom-width:10px;border-color:hsl(250,7%,92%);}.verification{color:hsl(180,61%,50%);}.gray{color:darkgray;}.right{float:right;}.clear{clear:both;}/*Terminal decorations*/.italic{font-style:italic;}.bold{font-weight:bold;}.underline{text-decoration:underline;}.black{color:#000000;}.red{color:#c75646;}.green{color:#8eb33b;}.yellow{color:#d0b03c;}.blue{color:#72b3cc;}.magenta{color:#c8a0d1;}.cyan{color:#218693;}.white{color:#b0b0b0;}.bg-black{background-color:#5d5d5d;}.bg-red{background-color:#e09690;}.bg-green{background-color:#cdee69;}.bg-yellow{background-color:#ffe337;}.bg-blue{background-color:#9cd9f0;}.bg-magenta{background-color:#fbb1f9;}.bg-cyan{background-color:#77dfd8;}.bg-white{background-color:#f7f7f7;}</style><style>.CodeRay {background-color:#FFF;border:1px solid #CCC;font-family:Monaco,"Courier New","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace;color:#000;padding:1em 0px 1em 1em;}.CodeRay pre {margin:0px;}div.CodeRay {}span.CodeRay {white-space:pre;border:0px;padding:2px }table.CodeRay {border-collapse:collapse;width:100%;padding:2px }table.CodeRay td {padding:1em 0.5em;vertical-align:top;}.CodeRay .line-numbers,.CodeRay .no {background-color:#ECECEC;color:#AAA;text-align:right;}.CodeRay .line-numbers a {color:#AAA;}.CodeRay .line-numbers tt {font-weight:bold }.CodeRay .line-numbers .highlighted {color:red }.CodeRay .line {display:block;float:left;width:100%;}.CodeRay span.line-numbers {padding:0px 4px }.CodeRay .code {width:100%}ol.CodeRay {font-size:10pt }ol.CodeRay li {white-space:pre }.CodeRay .code pre {overflow:auto }.CodeRay .debug {color:white !important;background:blue !important;}.CodeRay .annotation {color:#007 }.CodeRay .attribute-name {color:#f08 }.CodeRay .attribute-value {color:#700 }.CodeRay .binary {color:#509;font-weight:bold }.CodeRay .comment {color:#998;font-style:italic;}.CodeRay .char {color:#04D }.CodeRay .char .content {color:#04D }.CodeRay .char .delimiter {color:#039 }.CodeRay .class {color:#458;font-weight:bold }.CodeRay .complex {color:#A08;font-weight:bold }.CodeRay .constant {color:teal;}.CodeRay .color {color:#0A0 }.CodeRay .class-variable {color:#369 }.CodeRay .decorator {color:#B0B;}.CodeRay .definition {color:#099;font-weight:bold }.CodeRay .directive {color:#088;font-weight:bold }.CodeRay .delimiter {color:black }.CodeRay .doc {color:#970 }.CodeRay .doctype {color:#34b }.CodeRay .doc-string {color:#D42;font-weight:bold }.CodeRay .escape {color:#666;font-weight:bold }.CodeRay .entity {color:#800;font-weight:bold }.CodeRay .error {color:#F00;background-color:#FAA }.CodeRay .exception {color:#C00;font-weight:bold }.CodeRay .filename {color:#099;}.CodeRay .function {color:#900;font-weight:bold }.CodeRay .global-variable {color:teal;font-weight:bold }.CodeRay .hex {color:#058;font-weight:bold }.CodeRay .integer {color:#099;}.CodeRay .include {color:#B44;font-weight:bold }.CodeRay .inline {color:black }.CodeRay .inline .inline {background:#ccc }.CodeRay .inline .inline .inline {background:#bbb }.CodeRay .inline .inline-delimiter {color:#D14;}.CodeRay .inline-delimiter {color:#D14;}.CodeRay .important {color:#f00;}.CodeRay .interpreted {color:#B2B;font-weight:bold }.CodeRay .instance-variable {color:teal }.CodeRay .label {color:#970;font-weight:bold }.CodeRay .local-variable {color:#963 }.CodeRay .octal {color:#40E;font-weight:bold }.CodeRay .operator {}.CodeRay .predefined-constant {font-weight:bold }.CodeRay .predefined {color:#369;font-weight:bold }.CodeRay .preprocessor {color:#579;}.CodeRay .pseudo-class {color:#00C;font-weight:bold }.CodeRay .predefined-type {color:#074;font-weight:bold }.CodeRay .reserved,.keyword {color:#000;font-weight:bold }.CodeRay .key {color:#808;}.CodeRay .key .delimiter {color:#606;}.CodeRay .key .char {color:#80f;}.CodeRay .value {color:#088;}.CodeRay .regexp {background-color:#fff0ff }.CodeRay .regexp .content {color:#808 }.CodeRay .regexp .delimiter {color:#404 }.CodeRay .regexp .modifier {color:#C2C }.CodeRay .regexp .function {color:#404;font-weight:bold }.CodeRay .string {color:#D20;}.CodeRay .string .string {}.CodeRay .string .string .string {background-color:#ffd0d0 }.CodeRay .string .content {color:#D14;}.CodeRay .string .char {color:#D14;}.CodeRay .string .delimiter {color:#D14;}.CodeRay .shell {color:#D14 }.CodeRay .shell .content {}.CodeRay .shell .delimiter {color:#D14 }.CodeRay .symbol {color:#990073 }.CodeRay .symbol .content {color:#A60 }.CodeRay .symbol .delimiter {color:#630 }.CodeRay .tag {color:#070 }.CodeRay .tag-special {color:#D70;font-weight:bold }.CodeRay .type {color:#339;font-weight:bold }.CodeRay .variable {color:#036 }.CodeRay .insert {background:#afa;}.CodeRay .delete {background:#faa;}.CodeRay .change {color:#aaf;background:#007;}.CodeRay .head {color:#f8f;background:#505 }.CodeRay .insert .insert {color:#080;font-weight:bold }.CodeRay .delete .delete {color:#800;font-weight:bold }.CodeRay .change .change {color:#66f;}.CodeRay .head .head {color:#f4f;}</style><title>Array Developer&apos;s Chart</title></head><body id="dev"><div id="left"><span id="top-title">“Array” Developer&apos;s Chart</span><div class="p"><span class="head">Base Directory</span></div><code>/home/sawa/Dropbox/implicit/gem/manager/examples/array</code><div class="p"><span class="head">Files</span></div><div class="tablewrapper"><table id="files"><colgroup><col /><col /><col /><col /><col /></colgroup><tbody><tr><td>Category</td><td>Name</td><td>Version</td><td>Lines</td></tr><tr><td>Depended</td><td><code>ruby</code></td><td>2.3.1p112</td><td></td></tr><tr><td>Specification</td><td><code style="word-break:break-all;">spec</code></td><td><div class="bold">2016-04-25 22:36</div></td><td>3438</td></tr><tr><td>Unknown source</td><td /><td /><td></td></tr></tbody></table></div></div><div id="right"><div id="top"><span class="navigation"><span class="tag mode" onclick="displayMode(true, true)">Modules</span><span class="tag mode" onclick="displayMode(false, true)">Features</span><span class="tag mode" onclick="displayMode(false, false)">Full</span></span><span class="separator">│</span><span class="tag mode" onclick="toggleUserItems(this)">User Items</span><span class="separator">│</span><span class="navigation"><span class="tag private" onclick="toggleFeatures(this, 'private', 'user-feature-navigation1')">private</span> <span class="private" id="tagsum-private">1</span> <span class="tag public" onclick="toggleFeatures(this, 'public', 'user-feature-navigation1')">public</span> <span class="public" id="tagsum-public">97</span> <span id="user-feature-navigation1" data-tags="unimplemented protected private public"><span class="tag arrow" onclick="navigateTag(this.parentNode, -1)">◂</span><span class="tag arrow" onclick="navigateTag(this.parentNode, 1)">▸</span> <span class="statistics"><span class="current">1</span>/<span class="sum"></span>+<span class="excluded"></span></span> </span></span> <span class="navigation"><span class="tag singleton" onclick="toggleFeatures(this, 'singleton', 'user-feature-navigation2')">Singleton method</span> <span class="singleton" id="tagsum-singleton">3</span> <span class="tag instance" onclick="toggleFeatures(this, 'instance', 'user-feature-navigation2')">Instance method</span> <span class="instance" id="tagsum-instance">93</span> <span id="user-feature-navigation2" data-tags="constant singleton instance"><span class="tag arrow" onclick="navigateTag(this.parentNode, -1)">◂</span><span class="tag arrow" onclick="navigateTag(this.parentNode, 1)">▸</span> <span class="statistics"><span class="current">1</span>/<span class="sum"></span>+<span class="excluded"></span></span> </span></span> <span class="navigation"><span class="tag misplaced" onclick="toggleFeatures(this, 'misplaced', 'dev-feature-navigation1')">Misplaced</span> <span class="misplaced" id="tagsum-misplaced">4</span> <span id="dev-feature-navigation1" data-tags="undocumented hidden misplaced moved"><span class="tag arrow" onclick="navigateTag(this.parentNode, -1)">◂</span><span class="tag arrow" onclick="navigateTag(this.parentNode, 1)">▸</span> <span class="statistics"><span class="current">1</span>/<span class="sum"></span>+<span class="excluded"></span></span> </span></span> <span class="navigation"><span class="tag missing_doc" onclick="toggleAnchors(this, 'missing_doc', 'anchor-navigation1')">Missing doc</span> <span class="missing_doc" id="tagsum-missing_doc">4</span> <span id="anchor-navigation1" data-tags="missing_doc bad_doc agenda log"><span class="tag arrow" onclick="navigateTag(this.parentNode, -1)">◂</span><span class="tag arrow" onclick="navigateTag(this.parentNode, 1)">▸</span> <span class="statistics"><span class="current">1</span>/<span class="sum"></span>+<span class="excluded"></span></span> </span></span> <span class="navigation"><span class="tag missing_test" onclick="toggleAnchors(this, 'missing_test', 'anchor-navigation2')">Missing test</span> <span class="missing_test" id="tagsum-missing_test">27</span> <span class="tag bad_test" onclick="toggleAnchors(this, 'bad_test', 'anchor-navigation2')">Bad test</span> <span class="bad_test" id="tagsum-bad_test">1</span> <span class="tag untestable" onclick="toggleAnchors(this, 'untestable', 'anchor-navigation2')">Untestable</span> <span class="untestable" id="tagsum-untestable">2</span> <span class="tag bug" onclick="toggleAnchors(this, 'bug', 'anchor-navigation2')">Bug</span> <span class="bug" id="tagsum-bug">38</span> <span class="tag success" onclick="toggleAnchors(this, 'success', 'anchor-navigation2')">Success</span> <span class="success" id="tagsum-success">530</span> <span id="anchor-navigation2" data-tags="missing_test bad_test untestable bug success benchmark"><span class="tag arrow" onclick="navigateTag(this.parentNode, -1)">◂</span><span class="tag arrow" onclick="navigateTag(this.parentNode, 1)">▸</span> <span class="statistics"><span class="current">1</span>/<span class="sum"></span>+<span class="excluded"></span></span> </span></span></div><div id="main" onmouseover="this.focus()" onmouseout="this.blur()" tabindex="0"><div class="module"><div class="feature"><div></div><div class="feature-contents"><div class="user-item"><div class="p">Arrays are ordered, integer-indexed collections of any object.</div><div class="p"><code class="inline">Array</code> indexing starts at <code class="inline">0</code>, as in C or Java. A negative index is assumed to be relative to the end of the array---that is, an index of <code class="inline">-1</code> indicates the last element of the array, <code class="inline">-2</code> is the next to last element in the array, and so on.</div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature2">1. Creating Arrays</h2><div class="feature-contents"><div class="user-item"><div class="p">A new array can be created by using the literal constructor <code class="inline">[]</code>. Arrays can contain different types of objects. For example, the array below contains an <code class="inline">Integer</code>, a <code class="inline">String</code> and a <code class="inline">Float</code>:</div><div class="CodeRay">
2
+ <div class="code"><pre>ary = [<span class="integer">1</span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">two</span><span class="delimiter">&quot;</span></span>, <span class="float">3.0</span>] <span class="comment">#=&gt; [1, &quot;two&quot;, 3.0]</span>
3
+ </pre></div>
4
+ </div>
5
+ <div class="p">An array can also be created by explicitly calling <code class="inline">::new</code> with zero, one (the initial size of the <code class="inline">Array</code>), or two arguments (the initial size and a default object).</div><div class="CodeRay">
6
+ <div class="code"><pre>ary = <span class="constant">Array</span>.new <span class="comment">#=&gt; []</span>
7
+ <span class="constant">Array</span>.new(<span class="integer">3</span>) <span class="comment">#=&gt; [nil, nil, nil]</span>
8
+ <span class="constant">Array</span>.new(<span class="integer">3</span>, <span class="predefined-constant">true</span>) <span class="comment">#=&gt; [true, true, true]</span>
9
+ </pre></div>
10
+ </div>
11
+ <div class="p">Note that the second argument populates the array with references to the same object. Therefore, it is only recommended in cases when you need to instantiate arrays with natively immutable objects such as symbols, numbers, <code class="inline">true</code>, or <code class="inline">false</code>.</div><div class="p">To create an array with separate objects, a block can be passed instead. This method is safe to use with mutable objects such as hashes, strings, or other arrays:</div><div class="CodeRay">
12
+ <div class="code"><pre><span class="constant">Array</span>.new(<span class="integer">4</span>){<span class="constant">Hash</span>.new} <span class="comment">#=&gt; [{}, {}, {}, {}]</span>
13
+ </pre></div>
14
+ </div>
15
+ <div class="p">This is also a quick way to build up multi-dimensional arrays:</div><div class="CodeRay">
16
+ <div class="code"><pre>empty_table = <span class="constant">Array</span>.new(<span class="integer">3</span>){<span class="constant">Array</span>.new(<span class="integer">3</span>)}
17
+ <span class="comment">#=&gt; [[nil, nil, nil], [nil, nil, nil], [nil, nil, nil]]</span>
18
+ </pre></div>
19
+ </div>
20
+ <div class="p">An array can also be created by using the <code class="inline">Array()</code> method, provided by <code class="inline">Kernel</code>, which tries to call <code class="inline">to_ary</code>, then <code class="inline">to_a</code> on its argument.</div><div class="CodeRay">
21
+ <div class="code"><pre>Array({<span class="symbol">:a</span> =&gt; <span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="symbol">:b</span> =&gt; <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>}) <span class="comment">#=&gt; [[:a, &quot;a&quot;], [:b, &quot;b&quot;]]</span>
22
+ </pre></div>
23
+ </div>
24
+ </div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature3">2. Example Usage</h2><div class="feature-contents"><div class="user-item"><div class="p">In addition to the methods it mixes in through the <code class="inline">Enumerable</code> module, the <code class="inline">Array</code> class has proprietary methods for accessing, searching and otherwise manipulating arrays.</div><div class="p">Some of the more common ones are illustrated below.</div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature4">3. Accessing Elements</h2><div class="feature-contents"><div class="user-item"><div class="p">Elements in an array can be retrieved using the <code class="inline">#[]</code> method. It can take a single integer argument (a numeric index), a pair of arguments (start and length), or a range. Negative indices start counting from the end, with <code class="inline">-1</code> being the last element.</div><div class="CodeRay">
25
+ <div class="code"><pre>arr = [<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>, <span class="integer">4</span>, <span class="integer">5</span>, <span class="integer">6</span>]
26
+ arr[<span class="integer">2</span>] <span class="comment">#=&gt; 3</span>
27
+ arr[<span class="integer">100</span>] <span class="comment">#=&gt; nil</span>
28
+ arr[<span class="integer">-3</span>] <span class="comment">#=&gt; 4</span>
29
+ arr[<span class="integer">2</span>, <span class="integer">3</span>] <span class="comment">#=&gt; [3, 4, 5]</span>
30
+ arr[<span class="integer">1</span>..<span class="integer">4</span>] <span class="comment">#=&gt; [2, 3, 4, 5]</span>
31
+ arr[<span class="integer">1</span>..<span class="integer">-3</span>] <span class="comment">#=&gt; [2, 3, 4]</span>
32
+ </pre></div>
33
+ </div>
34
+ <div class="p">Another way to access a particular array element is by using the at method</div><div class="CodeRay">
35
+ <div class="code"><pre>arr.at(<span class="integer">0</span>) <span class="comment">#=&gt; 1</span>
36
+ </pre></div>
37
+ </div>
38
+ <div class="p">The slice method works in an identical manner to <code class="inline">#[]</code>.</div><div class="p">To raise an error for indices outside of the array bounds or else to provide a default value when that happens, you can use <code class="inline">fetch</code>.</div><div class="CodeRay">
39
+ <div class="code"><pre>arr = [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">d</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">e</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">f</span><span class="delimiter">&quot;</span></span>]
40
+ arr.fetch(<span class="integer">100</span>) <span class="comment">#=&gt; IndexError: index 100 outside of array bounds: -6...6</span>
41
+ arr.fetch(<span class="integer">100</span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">oops</span><span class="delimiter">&quot;</span></span>) <span class="comment">#=&gt; &quot;oops&quot;</span>
42
+ </pre></div>
43
+ </div>
44
+ <div class="p">The special methods <code class="inline">first</code> and <code class="inline">last</code> will return the first and last elements of an array, respectively.</div><div class="CodeRay">
45
+ <div class="code"><pre>arr.first <span class="comment">#=&gt; 1</span>
46
+ arr.last <span class="comment">#=&gt; 6</span>
47
+ </pre></div>
48
+ </div>
49
+ <div class="p">To return the first n elements of an array, use take</div><div class="CodeRay">
50
+ <div class="code"><pre>arr.take(<span class="integer">3</span>) <span class="comment">#=&gt; [1, 2, 3]</span>
51
+ </pre></div>
52
+ </div>
53
+ <div class="p"><code class="inline">drop</code> does the opposite of <code class="inline">take</code>, by returning the elements after n elements have been dropped:</div><div class="CodeRay">
54
+ <div class="code"><pre>arr.drop(<span class="integer">3</span>) <span class="comment">#=&gt; [4, 5, 6]</span>
55
+ </pre></div>
56
+ </div>
57
+ </div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature5">4. Obtaining Information about an Array</h2><div class="feature-contents"><div class="user-item"><div class="p">Arrays keep track of their own length at all times. To query an array about the number of elements it contains, use <code class="inline">length</code>, <code class="inline">count</code>, or <code class="inline">size</code>.</div><div class="CodeRay">
58
+ <div class="code"><pre>browsers = [<span class="string"><span class="delimiter">&quot;</span><span class="content">Chrome</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">Firefox</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">Safari</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">Opera</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">IE</span><span class="delimiter">&quot;</span></span>]
59
+ browsers.length <span class="comment">#=&gt; 5</span>
60
+ browsers.count <span class="comment">#=&gt; 5</span>
61
+ </pre></div>
62
+ </div>
63
+ <div class="p">To check whether an array contains any elements at all</div><div class="CodeRay">
64
+ <div class="code"><pre>browsers.empty? <span class="comment">#=&gt; false</span>
65
+ </pre></div>
66
+ </div>
67
+ <div class="p">To check whether a particular item is included in the array</div><div class="CodeRay">
68
+ <div class="code"><pre>browsers.include?(<span class="string"><span class="delimiter">&quot;</span><span class="content">Konqueror</span><span class="delimiter">&quot;</span></span>) <span class="comment">#=&gt; false</span>
69
+ </pre></div>
70
+ </div>
71
+ </div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature6">5. Adding Items to Arrays</h2><div class="feature-contents"><div class="user-item"><div class="p">Items can be added to the end of an array by using either <code class="inline">push</code> or <code class="inline">&lt;&lt;</code></div><div class="CodeRay">
72
+ <div class="code"><pre>arr = [<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>, <span class="integer">4</span>]
73
+ arr.push(<span class="integer">5</span>) <span class="comment">#=&gt; [1, 2, 3, 4, 5]</span>
74
+ arr &lt;&lt; <span class="integer">6</span> <span class="comment">#=&gt; [1, 2, 3, 4, 5, 6]</span>
75
+ </pre></div>
76
+ </div>
77
+ <div class="p"><code class="inline">unshift</code> will add a new item to the beginning of an array.</div><div class="CodeRay">
78
+ <div class="code"><pre>arr.unshift(<span class="integer">0</span>) <span class="comment">#=&gt; [0, 1, 2, 3, 4, 5, 6]</span>
79
+ </pre></div>
80
+ </div>
81
+ <div class="p">With <code class="inline">insert</code>, you can add a new element to an array at any position.</div><div class="CodeRay">
82
+ <div class="code"><pre>arr.insert(<span class="integer">3</span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">apple</span><span class="delimiter">&quot;</span></span>) <span class="comment">#=&gt; [0, 1, 2, &quot;apple&quot;, 3, 4, 5, 6]</span>
83
+ </pre></div>
84
+ </div>
85
+ <div class="p">Using the <code class="inline">insert</code> method, you can also insert multiple values at once:</div><div class="CodeRay">
86
+ <div class="code"><pre>arr.insert(<span class="integer">3</span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">orange</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">pear</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">grapefruit</span><span class="delimiter">&quot;</span></span>)
87
+ <span class="comment">#=&gt; [0, 1, 2, &quot;orange&quot;, &quot;pear&quot;, &quot;grapefruit&quot;, &quot;apple&quot;, 3, 4, 5, 6]</span>
88
+ </pre></div>
89
+ </div>
90
+ </div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature7">6. Removing Items from an Array</h2><div class="feature-contents"><div class="user-item"><div class="p">The method <code class="inline">pop</code> removes the last element in an array and returns it:</div><div class="CodeRay">
91
+ <div class="code"><pre>arr = [<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>, <span class="integer">4</span>, <span class="integer">5</span>, <span class="integer">6</span>]
92
+ arr.pop <span class="comment">#=&gt; 6</span>
93
+ arr <span class="comment">#=&gt; [1, 2, 3, 4, 5]</span>
94
+ </pre></div>
95
+ </div>
96
+ <div class="p">To retrieve and at the same time remove the first item, use <code class="inline">shift</code>:</div><div class="CodeRay">
97
+ <div class="code"><pre>arr.shift <span class="comment">#=&gt; 1</span>
98
+ arr <span class="comment">#=&gt; [2, 3, 4, 5]</span>
99
+ </pre></div>
100
+ </div>
101
+ <div class="p">To delete an element at a particular index:</div><div class="CodeRay">
102
+ <div class="code"><pre>arr.delete_at(<span class="integer">2</span>) <span class="comment">#=&gt; 4</span>
103
+ arr <span class="comment">#=&gt; [2, 3, 5]</span>
104
+ </pre></div>
105
+ </div>
106
+ <div class="p">To delete a particular element anywhere in an array, use <code class="inline">delete</code>:</div><div class="CodeRay">
107
+ <div class="code"><pre>arr = [<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">2</span>, <span class="integer">3</span>]
108
+ arr.delete(<span class="integer">2</span>) <span class="comment">#=&gt; 2</span>
109
+ arr <span class="comment">#=&gt; [1,3]</span>
110
+ </pre></div>
111
+ </div>
112
+ <div class="p">A useful method if you need to remove <code class="inline">nil</code> values from an array is <code class="inline">compact</code>:</div><div class="CodeRay">
113
+ <div class="code"><pre>arr = [<span class="string"><span class="delimiter">&quot;</span><span class="content">foo</span><span class="delimiter">&quot;</span></span>, <span class="integer">0</span>, <span class="predefined-constant">nil</span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">bar</span><span class="delimiter">&quot;</span></span>, <span class="integer">7</span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">baz</span><span class="delimiter">&quot;</span></span>, <span class="predefined-constant">nil</span>]
114
+ arr.compact <span class="comment">#=&gt; [&quot;foo&quot;, 0, &quot;bar&quot;, 7, &quot;baz&quot;]</span>
115
+ arr <span class="comment">#=&gt; [&quot;foo&quot;, 0, nil, &quot;bar&quot;, 7, &quot;baz&quot;, nil]</span>
116
+ arr.compact! <span class="comment">#=&gt; [&quot;foo&quot;, 0, &quot;bar&quot;, 7, &quot;baz&quot;]</span>
117
+ arr <span class="comment">#=&gt; [&quot;foo&quot;, 0, &quot;bar&quot;, 7, &quot;baz&quot;]</span>
118
+ </pre></div>
119
+ </div>
120
+ <div class="p">Another common need is to remove duplicate elements from an array.</div><div class="p">It has the non-destructive <code class="inline">uniq</code>, and destructive method <code class="inline">uniq!</code></div><div class="CodeRay">
121
+ <div class="code"><pre>arr = [<span class="integer">2</span>, <span class="integer">5</span>, <span class="integer">6</span>, <span class="integer">556</span>, <span class="integer">6</span>, <span class="integer">6</span>, <span class="integer">8</span>, <span class="integer">9</span>, <span class="integer">0</span>, <span class="integer">123</span>, <span class="integer">556</span>]
122
+ arr.uniq <span class="comment">#=&gt; [2, 5, 6, 556, 8, 9, 0, 123]</span>
123
+ </pre></div>
124
+ </div>
125
+ </div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature8">7. Iterating over Arrays</h2><div class="feature-contents"><div class="user-item"><div class="p">Like all classes that include the <code class="inline">Enumerable</code> module, <code class="inline">Array</code> has an each method, which defines what elements should be iterated over and how. In case of <code class="inline">Array</code>’s <code class="inline">each</code>, all elements in the <code class="inline">Array</code> instance are yielded to the supplied block in sequence.</div><div class="p">Note that this operation leaves the array unchanged.</div><div class="CodeRay">
126
+ <div class="code"><pre>arr = [<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>, <span class="integer">4</span>, <span class="integer">5</span>]
127
+ arr.each{|a| print a -= <span class="integer">10</span>, <span class="string"><span class="delimiter">&quot;</span><span class="content"> </span><span class="delimiter">&quot;</span></span>}
128
+ <span class="comment"># prints: -9 -8 -7 -6 -5</span>
129
+ <span class="comment">#=&gt; [1, 2, 3, 4, 5]</span>
130
+ </pre></div>
131
+ </div>
132
+ <div class="p">Another sometimes useful iterator is <code class="inline">reverse_each</code> which will iterate over the elements in the array in reverse order.</div><div class="CodeRay">
133
+ <div class="code"><pre>words = <span class="string"><span class="delimiter">%w[</span><span class="content">first second third fourth fifth sixth</span><span class="delimiter">]</span></span>
134
+ str = <span class="string"><span class="delimiter">&quot;</span><span class="delimiter">&quot;</span></span>
135
+ words.reverse_each{|word| str += <span class="string"><span class="delimiter">&quot;</span><span class="char">\#</span><span class="char">\{</span><span class="content">word</span><span class="char">\}</span><span class="content"> </span><span class="delimiter">&quot;</span></span>}
136
+ p str <span class="comment">#=&gt; &quot;sixth fifth fourth third second first &quot;</span>
137
+ </pre></div>
138
+ </div>
139
+ <div class="p">The <code class="inline">map</code> method can be used to create a new array based on the original array, but with the values modified by the supplied block:</div><div class="CodeRay">
140
+ <div class="code"><pre>arr.map{|a| <span class="integer">2</span>*a} <span class="comment">#=&gt; [2, 4, 6, 8, 10]</span>
141
+ arr <span class="comment">#=&gt; [1, 2, 3, 4, 5]</span>
142
+ arr.map!{|a| a**<span class="integer">2</span>} <span class="comment">#=&gt; [1, 4, 9, 16, 25]</span>
143
+ arr <span class="comment">#=&gt; [1, 4, 9, 16, 25]</span>
144
+ </pre></div>
145
+ </div>
146
+ </div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature9">8. Selecting Items from an Array</h2><div class="feature-contents"><div class="user-item"><div class="p">Elements can be selected from an array according to criteria defined in a block. The selection can happen in a destructive or a non-destructive manner. While the destructive operations will modify the array they were called on, the non-destructive methods usually return a new array with the selected elements, but leave the original array unchanged.</div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h3 id="feature10">8.1. Non-destructive Selection</h3><div class="feature-contents"><div class="user-item"><div class="CodeRay">
147
+ <div class="code"><pre>arr = [<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>, <span class="integer">4</span>, <span class="integer">5</span>, <span class="integer">6</span>]
148
+ arr.select{|a| a &gt; <span class="integer">3</span>} <span class="comment">#=&gt; [4, 5, 6]</span>
149
+ arr.reject{|a| a &lt; <span class="integer">3</span>} <span class="comment">#=&gt; [3, 4, 5, 6]</span>
150
+ arr.drop_while{|a| a &lt; <span class="integer">4</span>} <span class="comment">#=&gt; [4, 5, 6]</span>
151
+ arr <span class="comment">#=&gt; [1, 2, 3, 4, 5, 6]</span>
152
+ </pre></div>
153
+ </div>
154
+ </div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h3 id="feature11">8.2. Destructive Selection</h3><div class="feature-contents"><div class="user-item"><div class="p"><code class="inline">select!</code> and <code class="inline">reject!</code> are the corresponding destructive methods to <code class="inline">select</code> and <code class="inline">reject</code></div><div class="p">Similar to <code class="inline">select</code> vs. <code class="inline">reject</code>, <code class="inline">delete_if</code> and <code class="inline">keep_if</code> have the exact opposite result when supplied with the same block:</div><div class="CodeRay">
155
+ <div class="code"><pre>arr.delete_if{|a| a &lt; <span class="integer">4</span>} <span class="comment">#=&gt; [4, 5, 6]</span>
156
+ arr <span class="comment">#=&gt; [4, 5, 6]</span>
157
+ arr = [<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>, <span class="integer">4</span>, <span class="integer">5</span>, <span class="integer">6</span>]
158
+ arr.keep_if{|a| a &lt; <span class="integer">4</span>} <span class="comment">#=&gt; [1, 2, 3]</span>
159
+ arr <span class="comment">#=&gt; [1, 2, 3]</span>
160
+ </pre></div>
161
+ </div>
162
+ </div></div></div></div><div class="module"><div class="feature" onclick="toggleModuleContents(this)"><h1 class="module-header" id="feature12"><span class="anchor" id="public1"><span class="tag public">public</span></span> class <span class="feature-name">Array</span></h1><div class="feature-contents"><div class="dev-item"><div class="diagram"><div class="mixins"><div>Enumerable</div><div>┊</div><div class="baseline">Array</div></div> &lt; <div class="mixins"><div>Kernel</div><div>┊</div><div class="baseline">Object</div></div> &lt; <div class="mixins"><div class="baseline">BasicObject</div></div></div><div class="diagram"><div class="mixins"><div class="baseline">&lt;&lt;Array</div></div> &lt; <div class="mixins"><div class="baseline">&lt;&lt;Object</div></div> &lt; <div class="mixins"><div class="baseline">&lt;&lt;BasicObject</div></div> &lt; <div class="mixins"><div class="baseline">Class</div></div> &lt; <div class="mixins"><div class="baseline">Module</div></div> &lt; <div class="mixins"><div>Kernel</div><div>┊</div><div class="baseline">Object</div></div> &lt; <div class="mixins"><div class="baseline">BasicObject</div></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature13"><span class="anchor" id="public2"><span class="tag public">public</span></span> <span class="anchor" id="singleton1"><span class="tag singleton">1</span></span> Array.<span class="feature-name">[]</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">[]</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline">(*args)</code> → Array<div class="p">Returns a new array populated with the given objects.</div><div class="CodeRay">
163
+ <div class="code"><pre><span class="constant">Array</span>.[](<span class="integer">1</span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="regexp"><span class="delimiter">/</span><span class="content">^A</span><span class="delimiter">/</span></span>) <span class="comment"># =&gt; [1, &quot;a&quot;, /^A/]</span>
164
+ <span class="constant">Array</span>[<span class="integer">1</span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="regexp"><span class="delimiter">/</span><span class="content">^A</span><span class="delimiter">/</span></span>] <span class="comment"># =&gt; [1, &quot;a&quot;, /^A/]</span>
165
+ [<span class="integer">1</span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="regexp"><span class="delimiter">/</span><span class="content">^A</span><span class="delimiter">/</span></span>] <span class="comment"># =&gt; [1, &quot;a&quot;, /^A/]</span>
166
+ </pre></div>
167
+ </div>
168
+ </div><div class="dev-item"><div class="p"><span class="head">Test 1.</span> ruby/test/ruby/test_array.rb:test_01_square_brackets</div><div class="anchor" id="success1"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">1</span> <code class="inline">Array<span class="bold">[</span>5, 4, 3, 2, 1<span class="bold">]</span><span class="verification">.</span><span class="verification">instance_of?</span><span class="verification">(Array)</span></code></div></div><div class="anchor" id="success2"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">2</span> <code class="inline">RETURN<span class="verification">.</span><span class="verification">length</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> 5</span></code></div></div><div class="anchor" id="success3"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">3</span> <code class="inline">RETURN<span class="verification">[</span><span class="verification">0</span><span class="verification">]</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> 5</span></code></div></div><div class="anchor" id="success4"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">4</span> <code class="inline">RETURN<span class="verification">[</span><span class="verification">1</span><span class="verification">]</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> 4</span></code></div></div><div class="anchor" id="success5"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">5</span> <code class="inline">RETURN<span class="verification">[</span><span class="verification">2</span><span class="verification">]</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> 3</span></code></div></div><div class="anchor" id="success6"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">6</span> <code class="inline">RETURN<span class="verification">[</span><span class="verification">3</span><span class="verification">]</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> 2</span></code></div></div><div class="anchor" id="success7"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">7</span> <code class="inline">RETURN<span class="verification">[</span><span class="verification">4</span><span class="verification">]</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> 1</span></code></div></div><div class="anchor" id="success8"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">8</span> <code class="inline">RETURN<span class="verification">[</span><span class="verification">6</span><span class="verification">]</span><span class="verification"></span><span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature14"><span class="anchor" id="public3"><span class="tag public">public</span></span> <span class="anchor" id="singleton2"><span class="tag singleton">2</span></span> Array.<span class="feature-name">new</span> <span class="anchor" id="misplaced1"><span class="tag misplaced">Misplaced</span><span class="dev-text misplaced"> Defined on <code class="inline">Class</code>. </span></span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">new</code></li></ul></div></div><div class="user-item"><div class="p">Returns a new array.</div><span class="head">Usage</span> <code class="inline">(size = 0, obj = nil)</code> → Array<div class="p">If no arguments are sent, the new array will be empty. When a <code class="inline">size</code> and an optional <code class="inline">obj</code> are sent, an array is created with <code class="inline">size</code> copies of <code class="inline">obj</code>. Take notice that all elements will reference the same object <code class="inline">obj</code>.</div><span class="head">Usage</span> <code class="inline">(array)</code> → Array<div class="p">Creates a copy of the array passed as a parameter (the array is generated by calling <code class="inline">#to_ary</code> on the parameter).</div><div class="CodeRay">
169
+ <div class="code"><pre>first_array = [<span class="string"><span class="delimiter">&quot;</span><span class="content">Matz</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">Guido</span><span class="delimiter">&quot;</span></span>]
170
+ second_array = <span class="constant">Array</span>.new(first_array) <span class="comment">#=&gt; [&quot;Matz&quot;, &quot;Guido&quot;]</span>
171
+ first_array.equal? second_array <span class="comment">#=&gt; false</span>
172
+ </pre></div>
173
+ </div>
174
+ <span class="head">Usage</span> <code class="inline">(size){|index| block}</code> → Array<div class="p">An array of the given <code class="inline">size</code> is created. Each element in this array is created by passing the element’s index to the given block and storing the return value.</div><div class="CodeRay">
175
+ <div class="code"><pre><span class="constant">Array</span>.new(<span class="integer">3</span>){|index| index ** <span class="integer">2</span>}
176
+ <span class="comment"># =&gt; [0, 1, 4]</span>
177
+ </pre></div>
178
+ </div>
179
+ </div><div class="dev-item"><div class="p"><span class="head">Test 2.</span> ruby/test/ruby/test_array.rb:test_00_new</div><div class="anchor" id="success9"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">9</span> <code class="inline">Array.<span class="bold">new</span><span class="verification">.</span><span class="verification">instance_of?</span><span class="verification">(Array)</span></code></div></div><div class="anchor" id="success10"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">10</span> <code class="inline">RETURN<span class="verification">.</span><span class="verification">empty?</span><span class="verification"></span></code></div></div><div class="anchor" id="success11"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">11</span> <code class="inline">RETURN<span class="verification">[</span><span class="verification">0</span><span class="verification">]</span><span class="verification"></span><span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div></div><div class="user-item"><div class="p">Common gotchas</div><div class="p">When sending the second parameter, the same object will be used as the value for all the array elements:</div><div class="CodeRay">
180
+ <div class="code"><pre>a = <span class="constant">Array</span>.new(<span class="integer">2</span>, <span class="constant">Hash</span>.new)
181
+ <span class="comment"># =&gt; [{}, {}]</span>
182
+ a[<span class="integer">0</span>][<span class="string"><span class="delimiter">&quot;</span><span class="content">cat</span><span class="delimiter">&quot;</span></span>] = <span class="string"><span class="delimiter">&quot;</span><span class="content">feline</span><span class="delimiter">&quot;</span></span>
183
+ a <span class="comment"># =&gt; [{&quot;cat&quot;=&gt;&quot;feline&quot;}, {&quot;cat&quot;=&gt;&quot;feline&quot;}]</span>
184
+ a[<span class="integer">1</span>][<span class="string"><span class="delimiter">&quot;</span><span class="content">cat</span><span class="delimiter">&quot;</span></span>] = <span class="string"><span class="delimiter">&quot;</span><span class="content">Felix</span><span class="delimiter">&quot;</span></span>
185
+ a <span class="comment"># =&gt; [{&quot;cat&quot;=&gt;&quot;Felix&quot;}, {&quot;cat&quot;=&gt;&quot;Felix&quot;}]</span>
186
+ </pre></div>
187
+ </div>
188
+ <div class="p">Since all the <code class="inline">Array</code> elements store the same hash, changes to one of them will affect them all.</div><div class="p">If multiple copies are what you want, you should use the block version which uses the result of that block each time an element of the array needs to be initialized:</div><div class="CodeRay">
189
+ <div class="code"><pre>a = <span class="constant">Array</span>.new(<span class="integer">2</span>){<span class="constant">Hash</span>.new}
190
+ a[<span class="integer">0</span>][<span class="string"><span class="delimiter">&quot;</span><span class="content">cat</span><span class="delimiter">&quot;</span></span>] = <span class="string"><span class="delimiter">&quot;</span><span class="content">feline</span><span class="delimiter">&quot;</span></span>
191
+ a <span class="comment"># =&gt; [{&quot;cat&quot;=&gt;&quot;feline&quot;}, {}]</span>
192
+ </pre></div>
193
+ </div>
194
+ </div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature15"><span class="anchor" id="public4"><span class="tag public">public</span></span> <span class="anchor" id="singleton3"><span class="tag singleton">3</span></span> Array.<span class="feature-name">try_convert</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">try_convert</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline">(obj)</code> → Array | <code class="inline">nil</code><div class="p">Tries to convert <code class="inline">obj</code> into an array, using <code class="inline">to_ary</code> method. Returns the converted array or <code class="inline">nil</code> if obj cannot be converted for any reason. This method can be used to check if an argument is an array.</div><div class="CodeRay">
195
+ <div class="code"><pre><span class="constant">Array</span>.try_convert([<span class="integer">1</span>]) <span class="comment">#=&gt; [1]</span>
196
+ <span class="constant">Array</span>.try_convert(<span class="string"><span class="delimiter">&quot;</span><span class="content">1</span><span class="delimiter">&quot;</span></span>) <span class="comment">#=&gt; nil</span>
197
+ <span class="keyword">if</span> tmp = <span class="constant">Array</span>.try_convert(arg)
198
+ <span class="comment"># the argument is an array</span>
199
+ <span class="keyword">elsif</span> tmp = <span class="constant">String</span>.try_convert(arg)
200
+ <span class="comment"># the argument is a string</span>
201
+ <span class="keyword">end</span>
202
+ </pre></div>
203
+ </div>
204
+ </div><div class="dev-item"><div class="p"><span class="head">Test 3.</span> ruby/test/ruby/test_array.rb:test_try_convert</div><div class="anchor" id="success12"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">12</span> <code class="inline">Array.<span class="bold">try_convert</span>([1]) <span class="verification">==</span><span class="verification"> [1]</span></code></div></div><div class="anchor" id="success13"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">13</span> <code class="inline">Array.<span class="bold">try_convert</span>(&quot;1&quot;)<span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature16"><span class="anchor" id="public5"><span class="tag public">public</span></span> <span class="anchor" id="instance1"><span class="tag instance">1</span></span> Array#<span class="feature-name">&amp;</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">&amp;</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">[#uniq]</code>.</div><span class="head">Usage</span> <code class="inline">(other_ary)</code> → Array<div class="p">Set Intersection — Returns a new array containing elements common to the two arrays, excluding any duplicates. The order is preserved from the original array.</div><div class="p">It compares elements using their <code class="inline">hash</code> and <code class="inline">eql?</code> methods for efficiency.</div><div class="CodeRay">
205
+ <div class="code"><pre>[<span class="integer">1</span>, <span class="integer">1</span>, <span class="integer">3</span>, <span class="integer">5</span>] &amp; [<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>] <span class="comment">#=&gt; [1, 3]</span>
206
+ [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">z</span><span class="delimiter">&quot;</span></span>] &amp; [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>] <span class="comment">#=&gt; [&quot;a&quot;, &quot;b&quot;]</span>
207
+ </pre></div>
208
+ </div>
209
+ </div><div class="dev-item"><div class="p"><span class="head">Test 4.</span> ruby/test/ruby/test_array.rb:test_AND # &apos;&amp;&apos;</div><div class="anchor" id="success14"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">14</span> <code class="inline">([1, 1, 3, 5] <span class="bold">&amp;</span> [1, 2, 3]) <span class="verification">==</span><span class="verification"> [1, 3]</span></code></div></div><div class="anchor" id="success15"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">15</span> <code class="inline">([1, 1, 3, 5] <span class="bold">&amp;</span> []) <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="anchor" id="success16"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">16</span> <code class="inline">([] <span class="bold">&amp;</span> [1, 2, 3]) <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="anchor" id="success17"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">17</span> <code class="inline">([1, 2, 3] <span class="bold">&amp;</span> [4, 5, 6]) <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="p"><span class="head">Test 5.</span> ruby/test/ruby/test_array.rb:ruby/test/ruby/test_array_andor_0:1/2</div><div class="anchor" id="success18"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">18</span> <code class="inline">([1, 2, 3] <span class="bold">&amp;</span> [2, 4, 6]) <span class="verification">==</span><span class="verification"> [2]</span></code></div></div><div class="p"><span class="head">Test 6.</span> ruby/test/ruby/test_array.rb:test_0_literal:4/8</div><div class="anchor" id="success19"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">19</span> <code class="inline">([1, 2, 3] <span class="bold">&amp;</span> [2, 3, 4]) <span class="verification">==</span><span class="verification"> [2, 3]</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature17"><span class="anchor" id="public6"><span class="tag public">public</span></span> <span class="anchor" id="instance2"><span class="tag instance">2</span></span> Array#<span class="feature-name">*</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">*</code></li></ul></div></div><div class="user-item"><div class="p">Repetition</div><span class="head">Usage</span> <code class="inline">(str)</code> → String<div class="p">Equivalent to <code class="inline">self.join(str).</code></div><span class="head">Usage</span> <code class="inline">(int)</code> → Array<div class="p">Returns a new array built by concatenating the <code class="inline">int</code> copies of <code class="inline">self</code>.</div><div class="CodeRay">
210
+ <div class="code"><pre>[<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>] * <span class="integer">3</span> <span class="comment">#=&gt; [1, 2, 3, 1, 2, 3, 1, 2, 3]</span>
211
+ [<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>] * <span class="string"><span class="delimiter">&quot;</span><span class="content">,</span><span class="delimiter">&quot;</span></span> <span class="comment">#=&gt; &quot;1,2,3&quot;</span>
212
+ </pre></div>
213
+ </div>
214
+ </div><div class="dev-item"><div class="p"><span class="head">Test 7.</span> ruby/test/ruby/test_array.rb:test_MUL # &apos;*&apos;</div><div class="anchor" id="success20"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">20</span> <code class="inline">([] <span class="bold">*</span> 3) <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="anchor" id="success21"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">21</span> <code class="inline">([1] <span class="bold">*</span> 3) <span class="verification">==</span><span class="verification"> [1, 1, 1]</span></code></div></div><div class="anchor" id="success22"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">22</span> <code class="inline">([1, 2] <span class="bold">*</span> 3) <span class="verification">==</span><span class="verification"> [1, 2, 1, 2, 1, 2]</span></code></div></div><div class="anchor" id="success23"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">23</span> <code class="inline">([1, 2, 3] <span class="bold">*</span> 0) <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="anchor" id="success24"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">24</span> <code class="inline">([1, 2] <span class="bold">*</span> -3)<span class="verification">.</span><span class="verification">raise?</span><span class="verification">(ArgumentError)</span></code></div></div><div class="anchor" id="success25"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">25</span> <code class="inline">([1, 2, 3, 4, 5] <span class="bold">*</span> &quot;-&quot;) <span class="verification">==</span><span class="verification"> &quot;1-2-3-4-5&quot;</span></code></div></div><div class="anchor" id="success26"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">26</span> <code class="inline">([1, 2, 3, 4, 5] <span class="bold">*</span> &quot;&quot;) <span class="verification">==</span><span class="verification"> &quot;12345&quot;</span></code></div></div><div class="p"><span class="head">Test 8.</span> ruby/test/ruby/test_array.rb:test_times</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
215
+ <div class="code"><pre>longp = [<span class="integer">127</span>, <span class="integer">63</span>, <span class="integer">31</span>, <span class="integer">15</span>, <span class="integer">7</span>].map{|x| <span class="integer">2</span>**x-<span class="integer">1</span>}.find <span class="keyword">do</span>
216
+ |x|
217
+ <span class="keyword">begin</span>
218
+ [].first(x)
219
+ <span class="keyword">rescue</span> <span class="constant">ArgumentError</span>
220
+ <span class="predefined-constant">true</span>
221
+ <span class="keyword">rescue</span> <span class="constant">RangeError</span>
222
+ <span class="predefined-constant">false</span>
223
+ <span class="keyword">end</span>
224
+ <span class="keyword">end</span>
225
+ </pre></div>
226
+ </div>
227
+ <div class="anchor" id="success27"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">27</span> <code class="inline">([0, 0, 0, 0] <span class="bold">*</span> (longp + 1) / 4)<span class="verification">.</span><span class="verification">raise?</span><span class="verification">(ArgumentError)</span></code></div></div><div class="p"><span class="head">Test 9.</span> ruby/test/ruby/test_array.rb:test_0_literal:2/8</div><div class="anchor" id="success28"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">28</span> <code class="inline">([1, 2] <span class="bold">*</span> 2) <span class="verification">==</span><span class="verification"> [1, 2, 1, 2]</span></code></div></div><div class="anchor" id="success29"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">29</span> <code class="inline">([1, 2] <span class="bold">*</span> &quot;:&quot;) <span class="verification">==</span><span class="verification"> &quot;1:2&quot;</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature18"><span class="anchor" id="public7"><span class="tag public">public</span></span> <span class="anchor" id="instance3"><span class="tag instance">3</span></span> Array#<span class="feature-name">+</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">+</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">#concat</code>.</div><span class="head">Usage</span> <code class="inline">(other_ary)</code> → Array<div class="p">Concatenation — Returns a new array built by concatenating the two arrays together to produce a third array.</div><div class="CodeRay">
228
+ <div class="code"><pre>[<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>] + [<span class="integer">4</span>, <span class="integer">5</span>] <span class="comment">#=&gt; [1, 2, 3, 4, 5]</span>
229
+ a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>]
230
+ c = a + [<span class="string"><span class="delimiter">&quot;</span><span class="content">d</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">e</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">f</span><span class="delimiter">&quot;</span></span>]
231
+ c <span class="comment">#=&gt; [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;e&quot;, &quot;f&quot;]</span>
232
+ a <span class="comment">#=&gt; [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;]</span>
233
+ </pre></div>
234
+ </div>
235
+ </div><div class="dev-item"><div class="p"><span class="head">Test 10.</span> ruby/test/ruby/test_array.rb:test_PLUS # &apos;+&apos;</div><div class="anchor" id="success30"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">30</span> <code class="inline">([] <span class="bold">+</span> []) <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="anchor" id="success31"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">31</span> <code class="inline">([1] <span class="bold">+</span> []) <span class="verification">==</span><span class="verification"> [1]</span></code></div></div><div class="anchor" id="success32"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">32</span> <code class="inline">([] <span class="bold">+</span> [1]) <span class="verification">==</span><span class="verification"> [1]</span></code></div></div><div class="anchor" id="success33"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">33</span> <code class="inline">([1] <span class="bold">+</span> [1]) <span class="verification">==</span><span class="verification"> [1, 1]</span></code></div></div><div class="anchor" id="success34"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">34</span> <code class="inline">([&quot;cat&quot;, &quot;dog&quot;] <span class="bold">+</span> [1, 2, 3]) <span class="verification">==</span><span class="verification"> [&quot;cat&quot;, &quot;dog&quot;, 1, 2, 3]</span></code></div></div><div class="p"><span class="head">Test 11.</span> ruby/test/ruby/test_array.rb:test_0_literal:1/8</div><div class="anchor" id="success35"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">35</span> <code class="inline">([1, 2] <span class="bold">+</span> [3, 4]) <span class="verification">==</span><span class="verification"> [1, 2, 3, 4]</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature19"><span class="anchor" id="public8"><span class="tag public">public</span></span> <span class="anchor" id="instance4"><span class="tag instance">4</span></span> Array#<span class="feature-name">-</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">-</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline">(other_ary)</code> → Array<div class="p">Array Difference</div><div class="p">Returns a new array that is a copy of the original array, removing any items that also appear in <code class="inline">other_ary</code>. The order is preserved from the original array.</div><div class="p">It compares elements using their <code class="inline">hash</code> and <code class="inline">eql?</code> methods for efficiency.</div><div class="CodeRay">
236
+ <div class="code"><pre>[<span class="integer">1</span>, <span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">2</span>, <span class="integer">3</span>, <span class="integer">3</span>, <span class="integer">4</span>, <span class="integer">5</span>] - [<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">4</span>] <span class="comment">#=&gt; [3, 3, 5]</span>
237
+ </pre></div>
238
+ </div>
239
+ <div class="p">If you need set-like behavior, see the library class <code class="inline">Set</code>.</div></div><div class="dev-item"><div class="p"><span class="head">Test 12.</span> ruby/test/ruby/test_array.rb:test_MINUS # &apos;-&apos;</div><div class="anchor" id="success36"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">36</span> <code class="inline">([1] <span class="bold">-</span> [1]) <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="anchor" id="success37"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">37</span> <code class="inline">([1, 2, 3, 4, 5] <span class="bold">-</span> [2, 3, 4, 5]) <span class="verification">==</span><span class="verification"> [1]</span></code></div></div><div class="anchor" id="success38"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">38</span> <code class="inline">([1, 2, 1, 3, 1, 4, 1, 5] <span class="bold">-</span> [2, 3, 4, 5]) <span class="verification">==</span><span class="verification"> [1, 1, 1, 1]</span></code></div></div><div class="anchor" id="success39"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">39</span> <code class="inline">(1000.times.with_object(Array[]){|_, a| a &lt;&lt; 1} <span class="bold">-</span> [2]) <span class="verification">==</span><span class="verification"> Array[1] * 1000</span></code></div></div><div class="anchor" id="success40"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">40</span> <code class="inline">([1, 2, 1] <span class="bold">-</span> [2]) <span class="verification">==</span><span class="verification"> [1, 1]</span></code></div></div><div class="anchor" id="success41"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">41</span> <code class="inline">([1, 2, 3] <span class="bold">-</span> [4, 5, 6]) <span class="verification">==</span><span class="verification"> [1, 2, 3]</span></code></div></div><div class="p"><span class="head">Test 13.</span> ruby/test/ruby/test_array.rb:test_0_literal:6/8</div><div class="anchor" id="success42"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">42</span> <code class="inline">([1, 2, 3] <span class="bold">-</span> [2, 3]) <span class="verification">==</span><span class="verification"> [1]</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature20"><span class="anchor" id="public9"><span class="tag public">public</span></span> <span class="anchor" id="instance5"><span class="tag instance">5</span></span> Array#<span class="feature-name">&lt;&lt;</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">&lt;&lt;</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline">(obj)</code> → Array<div class="p">Append—Pushes the given object on to the end of this array. This expression returns the array itself, so several appends may be chained together.</div><div class="CodeRay">
240
+ <div class="code"><pre>[<span class="integer">1</span>, <span class="integer">2</span>] &lt;&lt; <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span> &lt;&lt; <span class="string"><span class="delimiter">&quot;</span><span class="content">d</span><span class="delimiter">&quot;</span></span> &lt;&lt; [<span class="integer">3</span>, <span class="integer">4</span>]
241
+ <span class="comment">#=&gt; [1, 2, &quot;c&quot;, &quot;d&quot;, [3, 4]]</span>
242
+ </pre></div>
243
+ </div>
244
+ </div><div class="dev-item"><div class="p"><span class="head">Test 14.</span> ruby/test/ruby/test_array.rb:test_LSHIFT # &apos;&lt;&lt;&apos;</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
245
+ <div class="code"><pre>a = <span class="constant">Array</span>[]</pre></div>
246
+ </div>
247
+ <div class="anchor" id="success43"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">43</span> <code class="inline">(a <span class="bold">&lt;&lt;</span> 1)<span class="verification">.</span><span class="verification">succeed?</span><span class="verification"></span></code></div></div><div class="anchor" id="success44"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">44</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1]</span></code></div></div><div class="anchor" id="success45"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">45</span> <code class="inline">((a &lt;&lt; 1) &lt;&lt; 2 <span class="bold">&lt;&lt;</span> 3)<span class="verification">.</span><span class="verification">succeed?</span><span class="verification"></span></code></div></div><div class="anchor" id="success46"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">46</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2, 3]</span></code></div></div><div class="anchor" id="success47"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">47</span> <code class="inline">((((a &lt;&lt; 1) &lt;&lt; 2) &lt;&lt; 3) &lt;&lt; nil <span class="bold">&lt;&lt;</span> &quot;cat&quot;)<span class="verification">.</span><span class="verification">succeed?</span><span class="verification"></span></code></div></div><div class="anchor" id="success48"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">48</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2, 3, nil, &quot;cat&quot;]</span></code></div></div><div class="anchor" id="success49"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">49</span> <code class="inline">(((((a &lt;&lt; 1) &lt;&lt; 2) &lt;&lt; 3) &lt;&lt; nil) &lt;&lt; &quot;cat&quot; <span class="bold">&lt;&lt;</span> a)<span class="verification">.</span><span class="verification">succeed?</span><span class="verification"></span></code></div></div><div class="anchor" id="success50"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">50</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> Array[1, 2, 3, nil, &quot;cat&quot;, a]</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature21"><span class="anchor" id="public10"><span class="tag public">public</span></span> <span class="anchor" id="instance6"><span class="tag instance">6</span></span> Array#<span class="feature-name">&lt;=&gt;</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">&lt;=&gt;</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline">(other_ary)</code> → <code class="inline">-1</code> | <code class="inline">0</code> | <code class="inline">1</code> | <code class="inline">nil</code><div class="p">Comparison — Returns an integer (<code class="inline">-1</code>, <code class="inline">0</code>, or <code class="inline">+1</code>) if this array is less than, equal to, or greater than <code class="inline">other_ary</code>.</div><div class="p"><code class="inline">nil</code> is returned if the two values are incomparable.</div><div class="p">Each object in each array is compared (using the <code class="inline">&lt;=&gt;</code> operator).</div><div class="p">Arrays are compared in an element-wise manner; the first two elements that are not equal will determine the return value for the whole comparison.</div><div class="p">If all the values are equal, then the return is based on a comparison of the array lengths. Thus, two arrays are equal according to <code class="inline">Array#&lt;=&gt;</code> if, and only if, they have the same length and the value of each element is equal to the value of the corresponding element in the other array.</div><div class="CodeRay">
248
+ <div class="code"><pre>[<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>] &lt;=&gt; [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>] <span class="comment">#=&gt; -1</span>
249
+ [<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>, <span class="integer">4</span>, <span class="integer">5</span>, <span class="integer">6</span>] &lt;=&gt; [<span class="integer">1</span>, <span class="integer">2</span>] <span class="comment">#=&gt; +1</span>
250
+ </pre></div>
251
+ </div>
252
+ </div><div class="dev-item"><div class="p"><span class="head">Test 15.</span> ruby/test/ruby/test_array.rb:test_CMP # &apos;&lt;=&gt;&apos;</div><div class="anchor" id="success51"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">51</span> <code class="inline">([] <span class="bold">&lt;=&gt;</span> [])<span class="verification">.</span><span class="verification">zero?</span><span class="verification"></span></code></div></div><div class="anchor" id="success52"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">52</span> <code class="inline">([1] <span class="bold">&lt;=&gt;</span> [1])<span class="verification">.</span><span class="verification">zero?</span><span class="verification"></span></code></div></div><div class="anchor" id="success53"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">53</span> <code class="inline">([1, 2, 3, &quot;cat&quot;] <span class="bold">&lt;=&gt;</span> [1, 2, 3, &quot;cat&quot;])<span class="verification">.</span><span class="verification">zero?</span><span class="verification"></span></code></div></div><div class="anchor" id="success54"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">54</span> <code class="inline">([] <span class="bold">&lt;=&gt;</span> [1]) <span class="verification">==</span><span class="verification"> -1</span></code></div></div><div class="anchor" id="success55"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">55</span> <code class="inline">([1] <span class="bold">&lt;=&gt;</span> []) <span class="verification">==</span><span class="verification"> 1</span></code></div></div><div class="anchor" id="success56"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">56</span> <code class="inline">([1, 2, 3] <span class="bold">&lt;=&gt;</span> [1, 2, 3, &quot;cat&quot;]) <span class="verification">==</span><span class="verification"> -1</span></code></div></div><div class="anchor" id="success57"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">57</span> <code class="inline">([1, 2, 3, &quot;cat&quot;] <span class="bold">&lt;=&gt;</span> [1, 2, 3]) <span class="verification">==</span><span class="verification"> 1</span></code></div></div><div class="anchor" id="success58"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">58</span> <code class="inline">([1, 2, 3, &quot;cat&quot;] <span class="bold">&lt;=&gt;</span> [1, 2, 3, &quot;dog&quot;]) <span class="verification">==</span><span class="verification"> -1</span></code></div></div><div class="anchor" id="success59"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">59</span> <code class="inline">([1, 2, 3, &quot;dog&quot;] <span class="bold">&lt;=&gt;</span> [1, 2, 3, &quot;cat&quot;]) <span class="verification">==</span><span class="verification"> 1</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature22"><span class="anchor" id="public11"><span class="tag public">public</span></span> <span class="anchor" id="instance7"><span class="tag instance">7</span></span> Array#<span class="feature-name">==</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">==</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline">(other_ary)</code> → <code class="inline">true</code> | <code class="inline">false</code><div class="p">Equality — Two arrays are equal if they contain the same number of elements and if each element is equal to (according to <code class="inline">Object#==</code>) the corresponding element in <code class="inline">other_ary</code>.</div><div class="CodeRay">
253
+ <div class="code"><pre>[<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>] == [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>, <span class="integer">7</span>] <span class="comment">#=&gt; false</span>
254
+ [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>, <span class="integer">7</span>] == [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>, <span class="integer">7</span>] <span class="comment">#=&gt; true</span>
255
+ [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>, <span class="integer">7</span>] == [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">d</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">f</span><span class="delimiter">&quot;</span></span>] <span class="comment">#=&gt; false</span>
256
+ </pre></div>
257
+ </div>
258
+ </div><div class="dev-item"><div class="p"><span class="head">Test 16.</span> ruby/test/ruby/test_array.rb:test_EQUAL # &apos;==&apos;</div><div class="anchor" id="success60"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">60</span> <code class="inline">([] <span class="bold">==</span> []) <span class="verification">==</span><span class="verification"> true</span></code></div></div><div class="anchor" id="success61"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">61</span> <code class="inline">([1] <span class="bold">==</span> [1]) <span class="verification">==</span><span class="verification"> true</span></code></div></div><div class="anchor" id="success62"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">62</span> <code class="inline">([1, 1, 2, 2] <span class="bold">==</span> [1, 1, 2, 2]) <span class="verification">==</span><span class="verification"> true</span></code></div></div><div class="anchor" id="success63"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">63</span> <code class="inline">([1, 1, 2, 2] <span class="bold">==</span> [1.0, 1.0, 2.0, 2.0]) <span class="verification">==</span><span class="verification"> true</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature23"><span class="anchor" id="public12"><span class="tag public">public</span></span> <span class="anchor" id="instance8"><span class="tag instance">8</span></span> Array#<span class="feature-name">===</span> <span class="anchor" id="misplaced2"><span class="tag misplaced">Misplaced</span><span class="dev-text misplaced"> Defined on <code class="inline">Kernel</code>. </span></span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">===</code></li></ul></div><div class="p"><span class="head">Test 17.</span> ruby/test/ruby/test_array.rb:test_VERY_EQUAL # &apos;===&apos;</div><div class="anchor" id="success64"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">64</span> <code class="inline">([] <span class="bold">===</span> []) <span class="verification">==</span><span class="verification"> true</span></code></div></div><div class="anchor" id="success65"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">65</span> <code class="inline">([1] <span class="bold">===</span> [1]) <span class="verification">==</span><span class="verification"> true</span></code></div></div><div class="anchor" id="success66"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">66</span> <code class="inline">([1, 1, 2, 2] <span class="bold">===</span> [1, 1, 2, 2]) <span class="verification">==</span><span class="verification"> true</span></code></div></div><div class="anchor" id="success67"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">67</span> <code class="inline">([1, 1, 2, 2] <span class="bold">===</span> [1.0, 1.0, 2.0, 2.0]) <span class="verification">==</span><span class="verification"> true</span></code></div></div><div class="p indent anchor" id="missing_doc1"><span class="hang-indent">​</span><span class="tag missing_doc">Missing Doc</span><span class="dev-text missing_doc"> No paragraph given for user.</span></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature24"><span class="anchor" id="public13"><span class="tag public">public</span></span> <span class="anchor" id="instance9"><span class="tag instance">9</span></span> Array#<span class="feature-name">[]</span> (alias: <span class="feature-name">slice</span>)</h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">[]</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline">(index)</code> → Object | <code class="inline">nil</code><span class="head">Usage</span> <code class="inline">(start, length)</code> → Array | <code class="inline">nil</code><span class="head">Usage</span> <code class="inline">(range)</code> → Array | <code class="inline">nil</code><div class="p">Element Reference — Returns the element at <code class="inline">index</code>, or returns a subarray starting at the <code class="inline">start</code> index and continuing for <code class="inline">length</code> elements, or returns a subarray specified by <code class="inline">range</code> of indices.</div><div class="p">Negative indices count backward from the end of the array (<code class="inline">-1</code> is the last element). For <code class="inline">start</code> and <code class="inline">range</code> cases, the starting index is just before an element. Additionally, an empty array is returned when the starting index for an element range is at the end of the array.</div><div class="p">Returns <code class="inline">nil</code> if the index (or starting index) are out of range.</div><div class="CodeRay">
259
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">d</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">e</span><span class="delimiter">&quot;</span></span>]
260
+ a[<span class="integer">2</span>] + a[<span class="integer">0</span>] + a[<span class="integer">1</span>] <span class="comment">#=&gt; &quot;cab&quot;</span>
261
+ a[<span class="integer">6</span>] <span class="comment">#=&gt; nil</span>
262
+ a[<span class="integer">1</span>, <span class="integer">2</span>] <span class="comment">#=&gt; [&quot;b&quot;, &quot;c&quot;]</span>
263
+ a[<span class="integer">1</span>..<span class="integer">3</span>] <span class="comment">#=&gt; [&quot;b&quot;, &quot;c&quot;, &quot;d&quot;]</span>
264
+ a[<span class="integer">4</span>..<span class="integer">7</span>] <span class="comment">#=&gt; [&quot;e&quot;]</span>
265
+ a[<span class="integer">6</span>..<span class="integer">10</span>] <span class="comment">#=&gt; nil</span>
266
+ a[<span class="integer">-3</span>, <span class="integer">3</span>] <span class="comment">#=&gt; [&quot;c&quot;, &quot;d&quot;, &quot;e&quot;]</span>
267
+ <span class="comment"># special cases</span>
268
+ a[<span class="integer">5</span>] <span class="comment">#=&gt; nil</span>
269
+ a[<span class="integer">6</span>, <span class="integer">1</span>] <span class="comment">#=&gt; nil</span>
270
+ a[<span class="integer">5</span>, <span class="integer">1</span>] <span class="comment">#=&gt; []</span>
271
+ a[<span class="integer">5</span>..<span class="integer">10</span>] <span class="comment">#=&gt; []</span>
272
+ </pre></div>
273
+ </div>
274
+ </div><div class="dev-item"><div class="p"><span class="head">Test 18.</span> ruby/test/ruby/test_array.rb:test_AREF # &apos;[]&apos;</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
275
+ <div class="code"><pre>a = <span class="constant">Array</span>[*(<span class="integer">1</span>..<span class="integer">100</span>).to_a]</pre></div>
276
+ </div>
277
+ <div class="anchor" id="success68"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">68</span> <code class="inline">a<span class="bold">[</span>0<span class="bold">]</span> <span class="verification">==</span><span class="verification"> 1</span></code></div></div><div class="anchor" id="success69"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">69</span> <code class="inline">a<span class="bold">[</span>99<span class="bold">]</span> <span class="verification">==</span><span class="verification"> 100</span></code></div></div><div class="anchor" id="success70"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">70</span> <code class="inline">a<span class="bold">[</span>100<span class="bold">]</span><span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="anchor" id="success71"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">71</span> <code class="inline">a<span class="bold">[</span>-1<span class="bold">]</span> <span class="verification">==</span><span class="verification"> 100</span></code></div></div><div class="anchor" id="success72"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">72</span> <code class="inline">a<span class="bold">[</span>-2<span class="bold">]</span> <span class="verification">==</span><span class="verification"> 99</span></code></div></div><div class="anchor" id="success73"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">73</span> <code class="inline">a<span class="bold">[</span>-100<span class="bold">]</span> <span class="verification">==</span><span class="verification"> 1</span></code></div></div><div class="anchor" id="success74"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">74</span> <code class="inline">a<span class="bold">[</span>-101<span class="bold">]</span><span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="anchor" id="success75"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">75</span> <code class="inline">a<span class="bold">[</span>-101, 0<span class="bold">]</span><span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="anchor" id="success76"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">76</span> <code class="inline">a<span class="bold">[</span>-101, 1<span class="bold">]</span><span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="anchor" id="success77"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">77</span> <code class="inline">a<span class="bold">[</span>-101, -1<span class="bold">]</span><span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="anchor" id="success78"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">78</span> <code class="inline">a<span class="bold">[</span>10, -1<span class="bold">]</span><span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="anchor" id="success79"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">79</span> <code class="inline">a<span class="bold">[</span>0, 1<span class="bold">]</span> <span class="verification">==</span><span class="verification"> [1]</span></code></div></div><div class="anchor" id="success80"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">80</span> <code class="inline">a<span class="bold">[</span>99, 1<span class="bold">]</span> <span class="verification">==</span><span class="verification"> [100]</span></code></div></div><div class="anchor" id="success81"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">81</span> <code class="inline">a<span class="bold">[</span>100, 1<span class="bold">]</span> <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="anchor" id="success82"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">82</span> <code class="inline">a<span class="bold">[</span>99, 100<span class="bold">]</span> <span class="verification">==</span><span class="verification"> [100]</span></code></div></div><div class="anchor" id="success83"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">83</span> <code class="inline">a<span class="bold">[</span>-1, 1<span class="bold">]</span> <span class="verification">==</span><span class="verification"> [100]</span></code></div></div><div class="anchor" id="success84"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">84</span> <code class="inline">a<span class="bold">[</span>-2, 1<span class="bold">]</span> <span class="verification">==</span><span class="verification"> [99]</span></code></div></div><div class="anchor" id="success85"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">85</span> <code class="inline">a<span class="bold">[</span>-100, 0<span class="bold">]</span> <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="anchor" id="success86"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">86</span> <code class="inline">a<span class="bold">[</span>-100, 1<span class="bold">]</span> <span class="verification">==</span><span class="verification"> [1]</span></code></div></div><div class="anchor" id="success87"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">87</span> <code class="inline">a<span class="bold">[</span>9, 3<span class="bold">]</span> <span class="verification">==</span><span class="verification"> [10, 11, 12]</span></code></div></div><div class="anchor" id="success88"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">88</span> <code class="inline">a<span class="bold">[</span>-91, 3<span class="bold">]</span> <span class="verification">==</span><span class="verification"> [10, 11, 12]</span></code></div></div><div class="anchor" id="success89"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">89</span> <code class="inline">a<span class="bold">[</span>0..0<span class="bold">]</span> <span class="verification">==</span><span class="verification"> [1]</span></code></div></div><div class="anchor" id="success90"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">90</span> <code class="inline">a<span class="bold">[</span>99..99<span class="bold">]</span> <span class="verification">==</span><span class="verification"> [100]</span></code></div></div><div class="anchor" id="success91"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">91</span> <code class="inline">a<span class="bold">[</span>100..100<span class="bold">]</span> <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="anchor" id="success92"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">92</span> <code class="inline">a<span class="bold">[</span>99..200<span class="bold">]</span> <span class="verification">==</span><span class="verification"> [100]</span></code></div></div><div class="anchor" id="success93"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">93</span> <code class="inline">a<span class="bold">[</span>-1..-1<span class="bold">]</span> <span class="verification">==</span><span class="verification"> [100]</span></code></div></div><div class="anchor" id="success94"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">94</span> <code class="inline">a<span class="bold">[</span>-2..-2<span class="bold">]</span> <span class="verification">==</span><span class="verification"> [99]</span></code></div></div><div class="anchor" id="success95"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">95</span> <code class="inline">a<span class="bold">[</span>9..11<span class="bold">]</span> <span class="verification">==</span><span class="verification"> [10, 11, 12]</span></code></div></div><div class="anchor" id="success96"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">96</span> <code class="inline">a<span class="bold">[</span>-91..-89<span class="bold">]</span> <span class="verification">==</span><span class="verification"> [10, 11, 12]</span></code></div></div><div class="anchor" id="success97"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">97</span> <code class="inline">a<span class="bold">[</span>10, -3<span class="bold">]</span><span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="anchor" id="success98"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">98</span> <code class="inline">a<span class="bold">[</span>10..7<span class="bold">]</span> <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="anchor" id="success99"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">99</span> <code class="inline">a<span class="bold">[</span>&quot;cat&quot;<span class="bold">]</span><span class="verification">.</span><span class="verification">raise?</span><span class="verification">(TypeError)</span></code></div></div><div class="p"><span class="head">Test 19.</span> ruby/test/ruby/test_array.rb:test_aref</div><div class="anchor" id="success100"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">100</span> <code class="inline">[]<span class="bold">[</span>0, 0, 0<span class="bold">]</span><span class="verification">.</span><span class="verification">raise?</span><span class="verification">(ArgumentError)</span></code></div></div><div class="p"><span class="head">Test 20.</span> ruby/test/ruby/test_array.rb:test_0_literal:7/8</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
278
+ <div class="code"><pre>x = [<span class="integer">0</span>, <span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>, <span class="integer">4</span>, <span class="integer">5</span>]</pre></div>
279
+ </div>
280
+ <div class="anchor" id="success101"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">101</span> <code class="inline">x<span class="bold">[</span>2<span class="bold">]</span> <span class="verification">==</span><span class="verification"> 2</span></code></div></div><div class="anchor" id="success102"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">102</span> <code class="inline">x<span class="bold">[</span>1..3<span class="bold">]</span> <span class="verification">==</span><span class="verification"> [1, 2, 3]</span></code></div></div><div class="anchor" id="success103"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">103</span> <code class="inline">x<span class="bold">[</span>1, 3<span class="bold">]</span> <span class="verification">==</span><span class="verification"> [1, 2, 3]</span></code></div></div><div class="p"><span class="head">Test 21.</span> ruby/test/ruby/test_array.rb:test_slice_frozen_array</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
281
+ <div class="code"><pre>a = [<span class="integer">1</span>,<span class="integer">2</span>,<span class="integer">3</span>,<span class="integer">4</span>,<span class="integer">5</span>]</pre></div>
282
+ </div>
283
+ <div class="anchor" id="success104"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">104</span> <code class="inline">a<span class="bold">[</span>0, 4<span class="bold">]</span> <span class="verification">==</span><span class="verification"> [1, 2, 3, 4]</span></code></div></div><div class="anchor" id="success105"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">105</span> <code class="inline">a<span class="bold">[</span>1, 4<span class="bold">]</span> <span class="verification">==</span><span class="verification"> [2, 3, 4, 5]</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature25"><span class="anchor" id="public14"><span class="tag public">public</span></span> <span class="anchor" id="instance10"><span class="tag instance">10</span></span> Array#<span class="feature-name">[]=</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">[]=</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">#push</code>, and <code class="inline">#unshift</code>.</div><span class="head">Usage</span> <code class="inline">(index, obj)</code> → Object<span class="head">Usage</span> <code class="inline">((start, length), obj)</code> → Object<span class="head">Usage</span> <code class="inline">(range, obj)</code> → Object<div class="p">Element Assignment — Sets the element at <code class="inline">index</code>, or replaces a subarray from the <code class="inline">start</code> index for <code class="inline">length</code> elements, or replaces a subarray specified by the <code class="inline">range</code> of indices.</div><div class="p">If indices are greater than the current capacity of the array, the array grows automatically. Elements are inserted into the array at <code class="inline">start</code> if <code class="inline">length</code> is zero.</div><div class="p">Negative indices will count backward from the end of the array. For <code class="inline">start</code> and <code class="inline">range</code> cases, the starting index is just before an element.</div><div class="p">An <code class="inline">IndexError</code> is raised if a negative index points past the beginning of the array.</div><div class="CodeRay">
284
+ <div class="code"><pre>a = <span class="constant">Array</span>.new
285
+ a[<span class="integer">4</span>] = <span class="string"><span class="delimiter">&quot;</span><span class="content">4</span><span class="delimiter">&quot;</span></span>; <span class="comment">#=&gt; [nil, nil, nil, nil, &quot;4&quot;]</span>
286
+ a[<span class="integer">0</span>, <span class="integer">3</span>] = [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>] <span class="comment">#=&gt; [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, nil, &quot;4&quot;]</span>
287
+ a[<span class="integer">1</span>..<span class="integer">2</span>] = [<span class="integer">1</span>, <span class="integer">2</span>] <span class="comment">#=&gt; [&quot;a&quot;, 1, 2, nil, &quot;4&quot;]</span>
288
+ a[<span class="integer">0</span>, <span class="integer">2</span>] = <span class="string"><span class="delimiter">&quot;</span><span class="content">?</span><span class="delimiter">&quot;</span></span> <span class="comment">#=&gt; [&quot;?&quot;, 2, nil, &quot;4&quot;]</span>
289
+ a[<span class="integer">0</span>..<span class="integer">2</span>] = <span class="string"><span class="delimiter">&quot;</span><span class="content">A</span><span class="delimiter">&quot;</span></span> <span class="comment">#=&gt; [&quot;A&quot;, &quot;4&quot;]</span>
290
+ a[<span class="integer">-1</span>] = <span class="string"><span class="delimiter">&quot;</span><span class="content">Z</span><span class="delimiter">&quot;</span></span> <span class="comment">#=&gt; [&quot;A&quot;, &quot;Z&quot;]</span>
291
+ a[<span class="integer">1</span>..<span class="integer">-1</span>] = <span class="predefined-constant">nil</span> <span class="comment">#=&gt; [&quot;A&quot;, nil]</span>
292
+ a[<span class="integer">1</span>..<span class="integer">-1</span>] = [] <span class="comment">#=&gt; [&quot;A&quot;]</span>
293
+ a[<span class="integer">0</span>, <span class="integer">0</span>] = [<span class="integer">1</span>, <span class="integer">2</span>] <span class="comment">#=&gt; [1, 2, &quot;A&quot;]</span>
294
+ a[<span class="integer">3</span>, <span class="integer">0</span>] = <span class="string"><span class="delimiter">&quot;</span><span class="content">B</span><span class="delimiter">&quot;</span></span> <span class="comment">#=&gt; [1, 2, &quot;A&quot;, &quot;B&quot;]</span>
295
+ </pre></div>
296
+ </div>
297
+ </div><div class="dev-item"><div class="p"><span class="head">Test 22.</span> ruby/test/ruby/test_array.rb:test_ASET # &apos;[]=&apos;</div><div class="anchor" id="success106"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">106</span> <code class="inline">(Array[*(0..99).to_a]<span class="bold">[</span>0<span class="bold">] = </span>0)<span class="verification">.</span><span class="verification">zero?</span><span class="verification"></span></code></div></div><div class="anchor" id="success107"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">107</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> Array[0] + Array[*(1..99).to_a]</span></code></div></div><div class="anchor" id="success108"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">108</span> <code class="inline">(Array[*(0..99).to_a]<span class="bold">[</span>10, 10<span class="bold">] = </span>0)<span class="verification">.</span><span class="verification">zero?</span><span class="verification"></span></code></div></div><div class="anchor" id="success109"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">109</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> Array[*(0..9).to_a] + Array[0] + Array[*(20..99).to_a]</span></code></div></div><div class="anchor" id="success110"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">110</span> <code class="inline">(Array[*(0..99).to_a]<span class="bold">[</span>-1<span class="bold">] = </span>0)<span class="verification">.</span><span class="verification">zero?</span><span class="verification"></span></code></div></div><div class="anchor" id="success111"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">111</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> Array[*(0..98).to_a] + Array[0]</span></code></div></div><div class="anchor" id="success112"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">112</span> <code class="inline">(Array[*(0..99).to_a]<span class="bold">[</span>-10, 10<span class="bold">] = </span>0)<span class="verification">.</span><span class="verification">zero?</span><span class="verification"></span></code></div></div><div class="anchor" id="success113"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">113</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> Array[*(0..89).to_a] + Array[0]</span></code></div></div><div class="anchor" id="success114"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">114</span> <code class="inline">(Array[*(0..99).to_a]<span class="bold">[</span>0, 1000<span class="bold">] = </span>0)<span class="verification">.</span><span class="verification">zero?</span><span class="verification"></span></code></div></div><div class="anchor" id="success115"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">115</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [0]</span></code></div></div><div class="anchor" id="success116"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">116</span> <code class="inline">(Array[*(0..99).to_a]<span class="bold">[</span>10..19<span class="bold">] = </span>0)<span class="verification">.</span><span class="verification">zero?</span><span class="verification"></span></code></div></div><div class="anchor" id="success117"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">117</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> Array[*(0..9).to_a] + Array[0] + Array[*(20..99).to_a]</span></code></div></div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
298
+ <div class="code"><pre>b = <span class="constant">Array</span>[*<span class="string"><span class="delimiter">%w(</span><span class="content">a b c</span><span class="delimiter">)</span></span>]</pre></div>
299
+ </div>
300
+ <div class="anchor" id="success118"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">118</span> <code class="inline">(Array[*(0..99).to_a]<span class="bold">[</span>0, 1<span class="bold">] = </span>b) <span class="verification">==</span><span class="verification"> b</span></code></div></div><div class="anchor" id="success119"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">119</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> b + Array[*(1..99).to_a]</span></code></div></div><div class="anchor" id="success120"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">120</span> <code class="inline">(Array[*(0..99).to_a]<span class="bold">[</span>10, 10<span class="bold">] = </span>b) <span class="verification">==</span><span class="verification"> b</span></code></div></div><div class="anchor" id="success121"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">121</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> Array[*(0..9).to_a] + b + Array[*(20..99).to_a]</span></code></div></div><div class="anchor" id="success122"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">122</span> <code class="inline">(Array[*(0..99).to_a]<span class="bold">[</span>-1, 1<span class="bold">] = </span>b) <span class="verification">==</span><span class="verification"> b</span></code></div></div><div class="anchor" id="success123"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">123</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> Array[*(0..98).to_a] + b</span></code></div></div><div class="anchor" id="success124"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">124</span> <code class="inline">(Array[*(0..99).to_a]<span class="bold">[</span>-10, 10<span class="bold">] = </span>b) <span class="verification">==</span><span class="verification"> b</span></code></div></div><div class="anchor" id="success125"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">125</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> Array[*(0..89).to_a] + b</span></code></div></div><div class="anchor" id="success126"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">126</span> <code class="inline">(Array[*(0..99).to_a]<span class="bold">[</span>0, 1000<span class="bold">] = </span>b) <span class="verification">==</span><span class="verification"> b</span></code></div></div><div class="anchor" id="success127"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">127</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> b</span></code></div></div><div class="anchor" id="success128"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">128</span> <code class="inline">(Array[*(0..99).to_a]<span class="bold">[</span>10..19<span class="bold">] = </span>b) <span class="verification">==</span><span class="verification"> b</span></code></div></div><div class="anchor" id="success129"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">129</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> Array[*(0..9).to_a] + b + Array[*(20..99).to_a]</span></code></div></div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
301
+ <div class="code"><pre>a = <span class="constant">Array</span>[<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>]</pre></div>
302
+ </div>
303
+ <div class="anchor" id="success130"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">130</span> <code class="inline">(a<span class="bold">[</span>1, 0<span class="bold">] = </span>a)<span class="verification">.</span><span class="verification">succeed?</span><span class="verification"></span></code></div></div><div class="anchor" id="success131"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">131</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 1, 2, 3, 2, 3]</span></code></div></div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
304
+ <div class="code"><pre>a = <span class="constant">Array</span>[<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>]</pre></div>
305
+ </div>
306
+ <div class="anchor" id="success132"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">132</span> <code class="inline">(a<span class="bold">[</span>-1, 0<span class="bold">] = </span>a)<span class="verification">.</span><span class="verification">succeed?</span><span class="verification"></span></code></div></div><div class="anchor" id="success133"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">133</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2, 1, 2, 3, 3]</span></code></div></div><div class="anchor" id="success134"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">134</span> <code class="inline">([]<span class="bold">[</span>5, 0<span class="bold">] = </span>[5])<span class="verification">.</span><span class="verification">succeed?</span><span class="verification"></span></code></div></div><div class="anchor" id="success135"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">135</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [nil, nil, nil, nil, nil, 5]</span></code></div></div><div class="anchor" id="success136"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">136</span> <code class="inline">([1]<span class="bold">[</span>1, 0<span class="bold">] = </span>[2])<span class="verification">.</span><span class="verification">succeed?</span><span class="verification"></span></code></div></div><div class="anchor" id="success137"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">137</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2]</span></code></div></div><div class="anchor" id="success138"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">138</span> <code class="inline">([1]<span class="bold">[</span>1, 1<span class="bold">] = </span>[2])<span class="verification">.</span><span class="verification">succeed?</span><span class="verification"></span></code></div></div><div class="anchor" id="success139"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">139</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2]</span></code></div></div><div class="p"><span class="head">Test 23.</span> ruby/test/ruby/test_array.rb:test_splice</div><div class="anchor" id="success140"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">140</span> <code class="inline">([0]<span class="bold">[</span>-2, 0<span class="bold">] = </span>nil)<span class="verification">.</span><span class="verification">raise?</span><span class="verification">(IndexError)</span></code></div></div><div class="p"><span class="head">Test 24.</span> ruby/test/ruby/test_array.rb:test_0_literal:8/8</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
307
+ <div class="code"><pre>x = [<span class="integer">0</span>, <span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>, <span class="integer">4</span>, <span class="integer">5</span>]</pre></div>
308
+ </div>
309
+ <div class="anchor" id="success141"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">141</span> <code class="inline">(x<span class="bold">[</span>0, 2<span class="bold">] = </span>10)<span class="verification">.</span><span class="verification">succeed?</span><span class="verification"></span></code></div></div><div class="anchor" id="success142"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">142</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [10, 2, 3, 4, 5]</span></code></div></div><div class="anchor" id="success143"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">143</span> <code class="inline">(x.tap{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:570)}<span class="bold">[</span>0, 0<span class="bold">] = </span>-1)<span class="verification">.</span><span class="verification">succeed?</span><span class="verification"></span></code></div></div><div class="anchor" id="success144"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">144</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [-1, 10, 2, 3, 4, 5]</span></code></div></div><div class="anchor" id="success145"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">145</span> <code class="inline">(x<span class="bold">[</span>-1, 1<span class="bold">] = </span>20)<span class="verification">.</span><span class="verification">succeed?</span><span class="verification"></span></code></div></div><div class="anchor" id="success146"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">146</span> <code class="inline">RECEIVER<span class="verification">[</span><span class="verification">-1</span><span class="verification">]</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> 20</span></code></div></div><div class="anchor" id="success147"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">147</span> <code class="inline">RECEIVER<span class="verification">.</span><span class="verification">pop</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> 20</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature26"><span class="anchor" id="public15"><span class="tag public">public</span></span> <span class="anchor" id="instance11"><span class="tag instance">11</span></span> Array#<span class="feature-name">assoc</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">assoc</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">#rassoc</code>.</div><span class="head">Usage</span> <code class="inline">(obj)</code> → Array | <code class="inline">nil</code><div class="p">Searches through an array whose elements are also arrays comparing <code class="inline">obj</code> with the first element of each contained array using <code class="inline">obj.==</code>.</div><div class="p">Returns the first contained array that matches (that is, the first associated array), or <code class="inline">nil</code> if no match is found.</div><div class="CodeRay">
310
+ <div class="code"><pre>s1 = [<span class="string"><span class="delimiter">&quot;</span><span class="content">colors</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">red</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">blue</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">green</span><span class="delimiter">&quot;</span></span>]
311
+ s2 = [<span class="string"><span class="delimiter">&quot;</span><span class="content">letters</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>]
312
+ s3 = <span class="string"><span class="delimiter">&quot;</span><span class="content">foo</span><span class="delimiter">&quot;</span></span>
313
+ a = [s1, s2, s3]
314
+ a.assoc(<span class="string"><span class="delimiter">&quot;</span><span class="content">letters</span><span class="delimiter">&quot;</span></span>) <span class="comment">#=&gt; [&quot;letters&quot;, &quot;a&quot;, &quot;b&quot;, &quot;c&quot;]</span>
315
+ a.assoc(<span class="string"><span class="delimiter">&quot;</span><span class="content">foo</span><span class="delimiter">&quot;</span></span>) <span class="comment">#=&gt; nil</span>
316
+ </pre></div>
317
+ </div>
318
+ </div><div class="dev-item"><div class="p"><span class="head">Test 25.</span> ruby/test/ruby/test_array.rb:test_assoc</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
319
+ <div class="code"><pre>a1 = <span class="constant">Array</span>[*<span class="string"><span class="delimiter">%w(</span><span class="content">cat feline</span><span class="delimiter">)</span></span>]
320
+ a2 = <span class="constant">Array</span>[*<span class="string"><span class="delimiter">%w(</span><span class="content">dog canine</span><span class="delimiter">)</span></span>]
321
+ a3 = <span class="constant">Array</span>[*<span class="string"><span class="delimiter">%w(</span><span class="content">mule asinine</span><span class="delimiter">)</span></span>]
322
+ a4 = <span class="constant">Array</span>[a1, a2, a3]
323
+ </pre></div>
324
+ </div>
325
+ <div class="anchor" id="success148"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">148</span> <code class="inline">a4.<span class="bold">assoc</span>(&quot;cat&quot;) <span class="verification">==</span><span class="verification"> a1</span></code></div></div><div class="anchor" id="success149"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">149</span> <code class="inline">a4.<span class="bold">assoc</span>(&quot;mule&quot;) <span class="verification">==</span><span class="verification"> a3</span></code></div></div><div class="anchor" id="success150"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">150</span> <code class="inline">a4.<span class="bold">assoc</span>(&quot;asinine&quot;)<span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="anchor" id="success151"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">151</span> <code class="inline">a4.<span class="bold">assoc</span>(&quot;wombat&quot;)<span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="anchor" id="success152"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">152</span> <code class="inline">a4.<span class="bold">assoc</span>(1..2)<span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature27"><span class="anchor" id="public16"><span class="tag public">public</span></span> <span class="anchor" id="instance12"><span class="tag instance">12</span></span> Array#<span class="feature-name">at</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">at</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">#[]</code>.</div><span class="head">Usage</span> <code class="inline">(index)</code> → Object | <code class="inline">nil</code><div class="p">Returns the element at <code class="inline">index</code>. A negative index counts from the end of <code class="inline">self</code>. Returns <code class="inline">nil</code> if the index is out of range.</div><div class="CodeRay">
326
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">d</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">e</span><span class="delimiter">&quot;</span></span>]
327
+ a.at(<span class="integer">0</span>) <span class="comment">#=&gt; &quot;a&quot;</span>
328
+ a.at(<span class="integer">-1</span>) <span class="comment">#=&gt; &quot;e&quot;</span>
329
+ </pre></div>
330
+ </div>
331
+ </div><div class="dev-item"><div class="p"><span class="head">Test 26.</span> ruby/test/ruby/test_array.rb:test_at</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
332
+ <div class="code"><pre>a = <span class="constant">Array</span>[*(<span class="integer">0</span>..<span class="integer">99</span>).to_a]</pre></div>
333
+ </div>
334
+ <div class="anchor" id="success153"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">153</span> <code class="inline">a.<span class="bold">at</span>(0)<span class="verification">.</span><span class="verification">zero?</span><span class="verification"></span></code></div></div><div class="anchor" id="success154"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">154</span> <code class="inline">a.<span class="bold">at</span>(10) <span class="verification">==</span><span class="verification"> 10</span></code></div></div><div class="anchor" id="success155"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">155</span> <code class="inline">a.<span class="bold">at</span>(99) <span class="verification">==</span><span class="verification"> 99</span></code></div></div><div class="anchor" id="success156"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">156</span> <code class="inline">a.<span class="bold">at</span>(100)<span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="anchor" id="success157"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">157</span> <code class="inline">a.<span class="bold">at</span>(-1) <span class="verification">==</span><span class="verification"> 99</span></code></div></div><div class="anchor" id="success158"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">158</span> <code class="inline">a.<span class="bold">at</span>(-100)<span class="verification">.</span><span class="verification">zero?</span><span class="verification"></span></code></div></div><div class="anchor" id="success159"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">159</span> <code class="inline">a.<span class="bold">at</span>(-101)<span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="anchor" id="success160"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">160</span> <code class="inline">a.<span class="bold">at</span>(&quot;cat&quot;)<span class="verification">.</span><span class="verification">raise?</span><span class="verification">(TypeError)</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature28"><span class="anchor" id="public17"><span class="tag public">public</span></span> <span class="anchor" id="instance13"><span class="tag instance">13</span></span> Array#<span class="feature-name">bsearch</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">bsearch</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline">{|x| block}</code> → Object<div class="p">By using binary search, finds a value from this array which meets the given condition in <code class="inline">O(log n)</code> where <code class="inline">n</code> is the size of the array.</div><div class="p">You can use this method in two use cases: a find-minimum mode and a find-any mode. In either case, the elements of the array must be monotone (or sorted) with respect to the block.</div><div class="p">In find-minimum mode (this is a good choice for typical use case), the block must return <code class="inline">true</code> or <code class="inline">false</code>, and there must be an index <code class="inline">i</code> (<code class="inline">0 &lt;= i &lt;= ary.size</code>) so that:</div><ul><li>the block returns <code class="inline">false</code> for any element whose index is less than <code class="inline">i</code>, and</li><li>the block returns <code class="inline">true</code> for any element whose index is greater than or equal to i.</li></ul><div class="p">This method returns the <code class="inline">i</code>-th element. If <code class="inline">i</code> is equal to <code class="inline">ary.size</code>, it returns <code class="inline">nil</code>.</div><div class="CodeRay">
335
+ <div class="code"><pre>ary = [<span class="integer">0</span>, <span class="integer">4</span>, <span class="integer">7</span>, <span class="integer">10</span>, <span class="integer">12</span>]
336
+ ary.bsearch{|x| x &gt;= <span class="integer">4</span>} <span class="comment">#=&gt; 4</span>
337
+ ary.bsearch{|x| x &gt;= <span class="integer">6</span>} <span class="comment">#=&gt; 7</span>
338
+ ary.bsearch{|x| x &gt;= <span class="integer">-1</span>} <span class="comment">#=&gt; 0</span>
339
+ ary.bsearch{|x| x &gt;= <span class="integer">100</span>} <span class="comment">#=&gt; nil</span>
340
+ </pre></div>
341
+ </div>
342
+ <div class="p">In find-any mode (this behaves like libc’s <code class="inline">bsearch(3)</code>), the block must return a number, and there must be two indices <code class="inline">i</code> and <code class="inline">j</code> (<code class="inline">0</code> &lt;= <code class="inline">i</code> &lt;= <code class="inline">j</code> &lt;= <code class="inline">ary.size</code>) so that:</div><ul><li>the block returns a positive number for ary if 0 &lt;= k &lt; i,</li><li>the block returns zero for ary if <code class="inline">i</code> &lt;= <code class="inline">k</code> &lt; <code class="inline">j</code>, and</li><li>the block returns a negative number for ary if <code class="inline">j</code> &lt;= <code class="inline">k</code> &lt; <code class="inline">ary.size</code>.</li></ul><div class="p">Under this condition, this method returns any element whose index is within <code class="inline">i…j</code>. If <code class="inline">i</code> is equal to <code class="inline">j</code> (i.e., there is no element that satisfies the block), this method returns <code class="inline">nil</code>.</div><div class="CodeRay">
343
+ <div class="code"><pre>ary = [<span class="integer">0</span>, <span class="integer">4</span>, <span class="integer">7</span>, <span class="integer">10</span>, <span class="integer">12</span>]
344
+ <span class="comment"># try to find v such that 4 &lt;= v &lt; 8</span>
345
+ ary.bsearch{|x| <span class="integer">1</span> - x / <span class="integer">4</span>} <span class="comment">#=&gt; 4 or 7</span>
346
+ <span class="comment"># try to find v such that 8 &lt;= v &lt; 10</span>
347
+ ary.bsearch{|x| <span class="integer">4</span> - x / <span class="integer">2</span>} <span class="comment">#=&gt; nil</span>
348
+ </pre></div>
349
+ </div>
350
+ <div class="p">You must not mix the two modes at a time; the block must always return either <code class="inline">true</code>/<code class="inline">false</code>, or always return a number. It is undefined which value is actually picked up at each iteration.</div></div><div class="dev-item"><div class="p"><span class="head">Test 27.</span> ruby/test/ruby/test_array.rb:test_bsearch_typechecks_return_values</div><div class="anchor" id="success161"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">161</span> <code class="inline">[1, 2, 42, 100, 666].<span class="bold">bsearch</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:651)}<span class="verification">.</span><span class="verification">raise?</span><span class="verification">(TypeError)</span></code></div></div><div class="anchor" id="success162"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">162</span> <code class="inline">[1, 2, 42, 100, 666].<span class="bold">bsearch</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:652)} <span class="verification">==</span><span class="verification"> nil</span></code></div></div><div class="p"><span class="head">Test 28.</span> ruby/test/ruby/test_array.rb:test_bsearch_with_no_block</div><div class="anchor" id="success163"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">163</span> <code class="inline">[1, 2, 42, 100, 666].<span class="bold">bsearch</span><span class="verification">.</span><span class="verification">succeed?</span><span class="verification"></span></code></div></div><div class="anchor" id="success164"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">164</span> <code class="inline">RETURN<span class="verification">.</span><span class="verification">size</span><span class="verification"></span><span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="anchor" id="success165"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">165</span> <code class="inline">RETURN<span class="verification">.</span><span class="verification">each</span><span class="verification">{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:656)}</span> <span class="verification">==</span><span class="verification"> 42</span></code></div></div><div class="p"><span class="head">Test 29.</span> ruby/test/ruby/test_array.rb:test_bsearch_in_find_minimum_mode</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
351
+ <div class="code"><pre>a = [<span class="integer">0</span>, <span class="integer">4</span>, <span class="integer">7</span>, <span class="integer">10</span>, <span class="integer">12</span>]</pre></div>
352
+ </div>
353
+ <div class="anchor" id="success166"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">166</span> <code class="inline">a.<span class="bold">bsearch</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:659)} <span class="verification">==</span><span class="verification"> 4</span></code></div></div><div class="anchor" id="success167"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">167</span> <code class="inline">a.<span class="bold">bsearch</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:660)} <span class="verification">==</span><span class="verification"> 7</span></code></div></div><div class="anchor" id="success168"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">168</span> <code class="inline">a.<span class="bold">bsearch</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:661)}<span class="verification">.</span><span class="verification">zero?</span><span class="verification"></span></code></div></div><div class="anchor" id="success169"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">169</span> <code class="inline">a.<span class="bold">bsearch</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:662)}<span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="p"><span class="head">Test 30.</span> ruby/test/ruby/test_array.rb:test_bsearch_in_find_any_mode</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
354
+ <div class="code"><pre>a = [<span class="integer">0</span>, <span class="integer">4</span>, <span class="integer">7</span>, <span class="integer">10</span>, <span class="integer">12</span>]</pre></div>
355
+ </div>
356
+ <div class="anchor" id="success170"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">170</span> <code class="inline">a.<span class="bold">bsearch</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:665)}<span class="verification">.</span><span class="verification">in?</span><span class="verification">([4, 7])</span></code></div></div><div class="anchor" id="success171"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">171</span> <code class="inline">a.<span class="bold">bsearch</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:666)}<span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="anchor" id="success172"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">172</span> <code class="inline">a.<span class="bold">bsearch</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:667)}<span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="anchor" id="success173"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">173</span> <code class="inline">a.<span class="bold">bsearch</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:668)}<span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="anchor" id="success174"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">174</span> <code class="inline">a.<span class="bold">bsearch</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:669)}<span class="verification">.</span><span class="verification">in?</span><span class="verification">([4, 7])</span></code></div></div><div class="anchor" id="success175"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">175</span> <code class="inline">a.<span class="bold">bsearch</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:670)}<span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="anchor" id="success176"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">176</span> <code class="inline">a.<span class="bold">bsearch</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:671)}<span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="anchor" id="success177"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">177</span> <code class="inline">a.<span class="bold">bsearch</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:672)}<span class="verification">.</span><span class="verification">in?</span><span class="verification">([4, 7])</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature29"><span class="anchor" id="public18"><span class="tag public">public</span></span> <span class="anchor" id="instance14"><span class="tag instance">14</span></span> Array#<span class="feature-name">clear</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">clear</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline"></code> → Array<div class="p">Removes all elements from <code class="inline">self</code>.</div><div class="CodeRay">
357
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">d</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">e</span><span class="delimiter">&quot;</span></span>]
358
+ a.clear <span class="comment">#=&gt; []</span>
359
+ </pre></div>
360
+ </div>
361
+ </div><div class="dev-item"><div class="p"><span class="head">Test 31.</span> ruby/test/ruby/test_array.rb:test_clear2</div><div class="anchor" id="success178"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">178</span> <code class="inline">([0] * 1024).<span class="bold">clear</span> <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="p"><span class="head">Test 32.</span> ruby/test/ruby/test_array.rb:test_clear</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
362
+ <div class="code"><pre>a = <span class="constant">Array</span>[<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>]</pre></div>
363
+ </div>
364
+ <div class="anchor" id="success179"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">179</span> <code class="inline">a.<span class="bold">clear</span> <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="anchor" id="success180"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">180</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="anchor" id="success181"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">181</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> a</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature30"><span class="anchor" id="public19"><span class="tag public">public</span></span> <span class="anchor" id="instance15"><span class="tag instance">15</span></span> Array#<span class="feature-name">collect</span> (alias: <span class="feature-name">map</span>)</h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">collect</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">Enumerable#collect</code>.</div><span class="head">Usage</span> <code class="inline">{|item| block}</code> → Array<div class="p">Invokes the given block once for each element of <code class="inline">self</code>.</div><div class="p">Creates a new array containing the values returned by the block.</div><span class="head">Usage</span> <code class="inline"></code> → Enumerator<div class="CodeRay">
365
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">d</span><span class="delimiter">&quot;</span></span>]
366
+ a.collect{|x| x + <span class="string"><span class="delimiter">&quot;</span><span class="content">!</span><span class="delimiter">&quot;</span></span>} <span class="comment">#=&gt; [&quot;a!&quot;, &quot;b!&quot;, &quot;c!&quot;, &quot;d!&quot;]</span>
367
+ a.map.with_index{|x, i| x * i} <span class="comment">#=&gt; [&quot;&quot;, &quot;b&quot;, &quot;cc&quot;, &quot;ddd&quot;]</span>
368
+ a <span class="comment">#=&gt; [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;]</span>
369
+ </pre></div>
370
+ </div>
371
+ </div><div class="dev-item"><div class="p indent anchor" id="missing_test1"><span class="hang-indent">​</span><span class="tag missing_test">Missing test</span><span class="dev-text missing_test"> Not unit tested.</span></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature31"><span class="anchor" id="public20"><span class="tag public">public</span></span> <span class="anchor" id="instance16"><span class="tag instance">16</span></span> Array#<span class="feature-name">collect!</span> (alias: <span class="feature-name">map!</span>)</h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">collect!</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">Enumerable#collect</code>.</div><span class="head">Usage</span> <code class="inline">{|item| block}</code> → Array<div class="p">Invokes the given block once for each element of self, replacing the element with the value returned by the block.</div><span class="head">Usage</span> <code class="inline"></code> → Enumerator<div class="CodeRay">
372
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">d</span><span class="delimiter">&quot;</span></span>]
373
+ a.map!{|x| x + <span class="string"><span class="delimiter">&quot;</span><span class="content">!</span><span class="delimiter">&quot;</span></span>}
374
+ a <span class="comment">#=&gt; [&quot;a!&quot;, &quot;b!&quot;, &quot;c!&quot;, &quot;d!&quot;]</span>
375
+ a.collect!.with_index{|x, i| x[<span class="integer">0</span>...i]}
376
+ a <span class="comment">#=&gt; [&quot;&quot;, &quot;b&quot;, &quot;c!&quot;, &quot;d!&quot;]</span>
377
+ </pre></div>
378
+ </div>
379
+ </div><div class="dev-item"><div class="p indent anchor" id="missing_test2"><span class="hang-indent">​</span><span class="tag missing_test">Missing test</span><span class="dev-text missing_test"> Not unit tested.</span></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature32"><span class="anchor" id="public21"><span class="tag public">public</span></span> <span class="anchor" id="instance17"><span class="tag instance">17</span></span> Array#<span class="feature-name">combination</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">combination</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline">(n){|c| block}</code> → Array<div class="p">When invoked with a block, yields all combinations of length <code class="inline">n</code> of elements from the array and then returns the array itself.</div><div class="p">The implementation makes no guarantees about the order in which the combinations are yielded.</div><span class="head">Usage</span> <code class="inline">(n)</code> → Enumerator<div class="p">Examples:</div><div class="CodeRay">
380
+ <div class="code"><pre>a = [<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>, <span class="integer">4</span>]
381
+ a.combination(<span class="integer">1</span>).to_a <span class="comment">#=&gt; [[1],[2],[3],[4]]</span>
382
+ a.combination(<span class="integer">2</span>).to_a <span class="comment">#=&gt; [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]</span>
383
+ a.combination(<span class="integer">3</span>).to_a <span class="comment">#=&gt; [[1,2,3],[1,2,4],[1,3,4],[2,3,4]]</span>
384
+ a.combination(<span class="integer">4</span>).to_a <span class="comment">#=&gt; [[1,2,3,4]]</span>
385
+ a.combination(<span class="integer">0</span>).to_a <span class="comment">#=&gt; [[]] # one combination of length 0</span>
386
+ a.combination(<span class="integer">5</span>).to_a <span class="comment">#=&gt; [] # no combinations of length 5</span>
387
+ </pre></div>
388
+ </div>
389
+ </div><div class="dev-item"><div class="p"><span class="head">Test 33.</span> ruby/test/ruby/test_array.rb:test_combination</div><div class="anchor" id="success182"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">182</span> <code class="inline">[1, 2, 3, 4].<span class="bold">combination</span>(0)<span class="verification">.</span><span class="verification">to_a</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> [[]]</span></code></div></div><div class="anchor" id="success183"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">183</span> <code class="inline">[1, 2, 3, 4].<span class="bold">combination</span>(1)<span class="verification">.</span><span class="verification">to_a</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> [[1], [2], [3], [4]]</span></code></div></div><div class="anchor" id="success184"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">184</span> <code class="inline">[1, 2, 3, 4].<span class="bold">combination</span>(2)<span class="verification">.</span><span class="verification">to_a</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]]</span></code></div></div><div class="anchor" id="success185"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">185</span> <code class="inline">[1, 2, 3, 4].<span class="bold">combination</span>(3)<span class="verification">.</span><span class="verification">to_a</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> [[1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]]</span></code></div></div><div class="anchor" id="success186"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">186</span> <code class="inline">[1, 2, 3, 4].<span class="bold">combination</span>(4)<span class="verification">.</span><span class="verification">to_a</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> [[1, 2, 3, 4]]</span></code></div></div><div class="anchor" id="success187"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">187</span> <code class="inline">[1, 2, 3, 4].<span class="bold">combination</span>(5)<span class="verification">.</span><span class="verification">to_a</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="p"><span class="head">Test 34.</span> ruby/test/ruby/test_array.rb:test_combination2</div><div class="p"><span class="head">Test 34.1.</span> ruby-core:29240 Must be yielded even if 100C50 &gt; signed integer</div><div class="anchor" id="bug1"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">1</span> <code class="inline">[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100].<span class="bold">combination</span>(50){(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:739)} <span class="verification">==</span><span class="verification"> :called</span></code></div><ul><li><code class="inline">combination</code>: <span class="dev-text bug">LocalJumpError. Break from proc-closure.</span><table class="backtrace"><colgroup><col /><col /></colgroup><tbody><tr><td><code>spec:739</code></td><td><code class="inline"></code></td></tr></tbody></table></li></ul></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature33"><span class="anchor" id="public22"><span class="tag public">public</span></span> <span class="anchor" id="instance18"><span class="tag instance">18</span></span> Array#<span class="feature-name">compact</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">compact</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline"></code> → Array<div class="p">Returns a copy of <code class="inline">self</code> with all <code class="inline">nil</code> elements removed.</div><div class="CodeRay">
390
+ <div class="code"><pre>[<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="predefined-constant">nil</span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="predefined-constant">nil</span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>, <span class="predefined-constant">nil</span>].compact
391
+ <span class="comment">#=&gt; [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;]</span>
392
+ </pre></div>
393
+ </div>
394
+ </div><div class="dev-item"><div class="p"><span class="head">Test 35.</span> ruby/test/ruby/test_array.rb:test_compact_0:1/2</div><div class="anchor" id="success188"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">188</span> <code class="inline">[nil, 1, nil, nil, 5, nil, nil].<span class="bold">compact</span> <span class="verification">==</span><span class="verification"> [1, 5]</span></code></div></div><div class="anchor" id="success189"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">189</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [nil, 1, nil, nil, 5, nil, nil]</span></code></div></div><div class="p"><span class="head">Test 36.</span> ruby/test/ruby/test_array.rb:test_compact</div><div class="anchor" id="success190"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">190</span> <code class="inline">[1, nil, nil, 2, 3, nil, 4].<span class="bold">compact</span> <span class="verification">==</span><span class="verification"> [1, 2, 3, 4]</span></code></div></div><div class="anchor" id="success191"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">191</span> <code class="inline">[nil, 1, nil, 2, 3, nil, 4].<span class="bold">compact</span> <span class="verification">==</span><span class="verification"> [1, 2, 3, 4]</span></code></div></div><div class="anchor" id="success192"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">192</span> <code class="inline">[1, nil, nil, 2, 3, nil, 4, nil].<span class="bold">compact</span> <span class="verification">==</span><span class="verification"> [1, 2, 3, 4]</span></code></div></div><div class="anchor" id="success193"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">193</span> <code class="inline">[1, 2, 3, 4].<span class="bold">compact</span> <span class="verification">==</span><span class="verification"> [1, 2, 3, 4]</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature34"><span class="anchor" id="public23"><span class="tag public">public</span></span> <span class="anchor" id="instance19"><span class="tag instance">19</span></span> Array#<span class="feature-name">compact!</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">compact!</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline"></code> → Array | <code class="inline">nil</code><div class="p">Removes <code class="inline">nil</code> elements from the array.</div><div class="p">Returns <code class="inline">nil</code> if no changes were made, otherwise returns the array.</div><div class="CodeRay">
395
+ <div class="code"><pre>[<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="predefined-constant">nil</span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="predefined-constant">nil</span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>].compact! <span class="comment">#=&gt; [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;]</span>
396
+ [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>].compact! <span class="comment">#=&gt; nil</span>
397
+ </pre></div>
398
+ </div>
399
+ </div><div class="dev-item"><div class="p"><span class="head">Test 37.</span> ruby/test/ruby/test_array.rb:test_compact!</div><div class="anchor" id="success194"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">194</span> <code class="inline">[1, nil, nil, 2, 3, nil, 4].<span class="bold">compact!</span> <span class="verification">==</span><span class="verification"> [1, 2, 3, 4]</span></code></div></div><div class="anchor" id="success195"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">195</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2, 3, 4]</span></code></div></div><div class="anchor" id="success196"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">196</span> <code class="inline">[nil, 1, nil, 2, 3, nil, 4].<span class="bold">compact!</span> <span class="verification">==</span><span class="verification"> [1, 2, 3, 4]</span></code></div></div><div class="anchor" id="success197"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">197</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2, 3, 4]</span></code></div></div><div class="anchor" id="success198"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">198</span> <code class="inline">[1, nil, nil, 2, 3, nil, 4, nil].<span class="bold">compact!</span> <span class="verification">==</span><span class="verification"> [1, 2, 3, 4]</span></code></div></div><div class="anchor" id="success199"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">199</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2, 3, 4]</span></code></div></div><div class="anchor" id="success200"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">200</span> <code class="inline">[1, 2, 3, 4].<span class="bold">compact!</span><span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="anchor" id="success201"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">201</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2, 3, 4]</span></code></div></div><div class="p"><span class="head">Test 38.</span> ruby/test/ruby/test_array.rb:test_compact_0:2/2</div><div class="anchor" id="success202"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">202</span> <code class="inline">[nil, 1, nil, nil, 5, nil, nil].<span class="bold">compact!</span><span class="verification">.</span><span class="verification">succeed?</span><span class="verification"></span></code></div></div><div class="anchor" id="success203"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">203</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 5]</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature35"><span class="anchor" id="public24"><span class="tag public">public</span></span> <span class="anchor" id="instance20"><span class="tag instance">20</span></span> Array#<span class="feature-name">concat</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">concat</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">Array#+</code>.</div><span class="head">Usage</span> <code class="inline">(other_ary)</code> → Array<div class="p">Appends the elements of <code class="inline">other_ary</code> to <code class="inline">self</code>.</div><div class="CodeRay">
400
+ <div class="code"><pre>[<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>].concat([<span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">d</span><span class="delimiter">&quot;</span></span>]) <span class="comment">#=&gt; [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;]</span>
401
+ a = [<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>]
402
+ a.concat([<span class="integer">4</span>, <span class="integer">5</span>])
403
+ a <span class="comment">#=&gt; [1, 2, 3, 4, 5]</span>
404
+ </pre></div>
405
+ </div>
406
+ </div><div class="dev-item"><div class="p"><span class="head">Test 39.</span> ruby/test/ruby/test_array.rb:test_concat</div><div class="anchor" id="success204"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">204</span> <code class="inline">[1, 2].<span class="bold">concat</span>([3, 4]) <span class="verification">==</span><span class="verification"> [1, 2, 3, 4]</span></code></div></div><div class="anchor" id="success205"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">205</span> <code class="inline">[].<span class="bold">concat</span>([1, 2, 3, 4]) <span class="verification">==</span><span class="verification"> [1, 2, 3, 4]</span></code></div></div><div class="anchor" id="success206"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">206</span> <code class="inline">[1, 2, 3, 4].<span class="bold">concat</span>([]) <span class="verification">==</span><span class="verification"> [1, 2, 3, 4]</span></code></div></div><div class="anchor" id="success207"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">207</span> <code class="inline">[].<span class="bold">concat</span>([]) <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="anchor" id="success208"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">208</span> <code class="inline">[[1, 2]].<span class="bold">concat</span>([[3, 4]]) <span class="verification">==</span><span class="verification"> [[1, 2], [3, 4]]</span></code></div></div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
407
+ <div class="code"><pre>a = <span class="constant">Array</span>[<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>]</pre></div>
408
+ </div>
409
+ <div class="anchor" id="success209"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">209</span> <code class="inline">a.<span class="bold">concat</span>(a)<span class="verification">.</span><span class="verification">succeed?</span><span class="verification"></span></code></div></div><div class="anchor" id="success210"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">210</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2, 3, 1, 2, 3]</span></code></div></div><div class="anchor" id="success211"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">211</span> <code class="inline">[0].<span class="bold">concat</span>(:foo)<span class="verification">.</span><span class="verification">raise?</span><span class="verification">(TypeError)</span></code></div></div><div class="anchor" id="success212"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">212</span> <code class="inline">[0].<span class="bold">concat</span>(:foo)<span class="verification">.</span><span class="verification">raise?</span><span class="verification">(RuntimeError)</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature36"><span class="anchor" id="public25"><span class="tag public">public</span></span> <span class="anchor" id="instance21"><span class="tag instance">21</span></span> Array#<span class="feature-name">count</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">count</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline">(count)</code> → Integer<div class="p">Returns the number of elements.</div><span class="head">Usage</span> <code class="inline">(obj)</code> → Integer<div class="p">Counts the number of elements which equal <code class="inline">obj</code> using <code class="inline">==</code>.</div><span class="head">Usage</span> <code class="inline">{|item| block}</code> → Integer<div class="p">Counts the number of elements for which the block returns a true value.</div><div class="CodeRay">
410
+ <div class="code"><pre>ary = [<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">4</span>, <span class="integer">2</span>]
411
+ ary.count <span class="comment">#=&gt; 4</span>
412
+ ary.count(<span class="integer">2</span>) <span class="comment">#=&gt; 2</span>
413
+ ary.count{|x| (x % <span class="integer">2</span>).zero?} <span class="comment">#=&gt; 3</span>
414
+ </pre></div>
415
+ </div>
416
+ </div><div class="dev-item"><div class="p indent anchor" id="missing_test3"><span class="hang-indent">​</span><span class="tag missing_test">Missing test</span><span class="dev-text missing_test"> Not unit tested.</span></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature37"><span class="anchor" id="public26"><span class="tag public">public</span></span> <span class="anchor" id="instance22"><span class="tag instance">22</span></span> Array#<span class="feature-name">cycle</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">cycle</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline">(n=nil){|obj| block}</code> → NilClass<div class="p">Calls the given block for each element <code class="inline">n</code> times or forever if <code class="inline">nil</code> is given.</div><div class="p">Does nothing if a non-positive number is given or the array is empty.</div><div class="p">Returns <code class="inline">nil</code> if the loop has finished without getting interrupted.</div><span class="head">Usage</span> <code class="inline">(n=nil)</code> → Enumerator<div class="CodeRay">
417
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>]
418
+ a.cycle{|x| puts x} <span class="comment"># print, a, b, c, a, b, c,.. forever.</span>
419
+ a.cycle(<span class="integer">2</span>){|x| puts x} <span class="comment"># print, a, b, c, a, b, c.</span>
420
+ </pre></div>
421
+ </div>
422
+ </div><div class="dev-item"><div class="p indent anchor" id="missing_test4"><span class="hang-indent">​</span><span class="tag missing_test">Missing test</span><span class="dev-text missing_test"> Not unit tested.</span></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature38"><span class="anchor" id="public27"><span class="tag public">public</span></span> <span class="anchor" id="instance23"><span class="tag instance">23</span></span> Array#<span class="feature-name">delete</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">delete</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline">(obj)</code> → Object | <code class="inline">nil</code><div class="p">Deletes all items from <code class="inline">self</code> that are equal to <code class="inline">obj</code>.</div><div class="p">Returns the last deleted item, or <code class="inline">nil</code> if no matching item is found.</div><span class="head">Usage</span> <code class="inline">(obj){block}</code> → Object<div class="p">The result of the block is returned if the item is not found. (To remove <code class="inline">nil</code> elements and get an informative return value, use <code class="inline">#compact!</code>)</div><div class="CodeRay">
423
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>]
424
+ a.delete(<span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>) <span class="comment">#=&gt; &quot;b&quot;</span>
425
+ a <span class="comment">#=&gt; [&quot;a&quot;, &quot;c&quot;]</span>
426
+ a.delete(<span class="string"><span class="delimiter">&quot;</span><span class="content">z</span><span class="delimiter">&quot;</span></span>) <span class="comment">#=&gt; nil</span>
427
+ a.delete(<span class="string"><span class="delimiter">&quot;</span><span class="content">z</span><span class="delimiter">&quot;</span></span>){<span class="string"><span class="delimiter">&quot;</span><span class="content">not found</span><span class="delimiter">&quot;</span></span>} <span class="comment">#=&gt; &quot;not found&quot;</span>
428
+ </pre></div>
429
+ </div>
430
+ </div><div class="dev-item"><div class="p"><span class="head">Test 40.</span> ruby/test/ruby/test_array.rb:test_delete</div><div class="anchor" id="success213"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">213</span> <code class="inline">Array[*(&quot;cab&quot;..&quot;cat&quot;).to_a].<span class="bold">delete</span>(&quot;cap&quot;) <span class="verification">==</span><span class="verification"> &quot;cap&quot;</span></code></div></div><div class="anchor" id="success214"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">214</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> Array[*(&quot;cab&quot;..&quot;cao&quot;).to_a] + Array[*(&quot;caq&quot;..&quot;cat&quot;).to_a]</span></code></div></div><div class="anchor" id="success215"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">215</span> <code class="inline">Array[*(&quot;cab&quot;..&quot;cat&quot;).to_a].<span class="bold">delete</span>(&quot;cab&quot;) <span class="verification">==</span><span class="verification"> &quot;cab&quot;</span></code></div></div><div class="anchor" id="success216"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">216</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> Array[*(&quot;cac&quot;..&quot;cat&quot;).to_a]</span></code></div></div><div class="anchor" id="success217"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">217</span> <code class="inline">Array[*(&quot;cab&quot;..&quot;cat&quot;).to_a].<span class="bold">delete</span>(&quot;cat&quot;) <span class="verification">==</span><span class="verification"> &quot;cat&quot;</span></code></div></div><div class="anchor" id="success218"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">218</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> Array[*(&quot;cab&quot;..&quot;cas&quot;).to_a]</span></code></div></div><div class="anchor" id="success219"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">219</span> <code class="inline">Array[*(&quot;cab&quot;..&quot;cat&quot;).to_a].<span class="bold">delete</span>(&quot;cup&quot;)<span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="anchor" id="success220"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">220</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> Array[*(&quot;cab&quot;..&quot;cat&quot;).to_a]</span></code></div></div><div class="anchor" id="success221"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">221</span> <code class="inline">Array[*(&quot;cab&quot;..&quot;cat&quot;).to_a].<span class="bold">delete</span>(&quot;cup&quot;){(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:848)} <span class="verification">==</span><span class="verification"> 99</span></code></div></div><div class="anchor" id="success222"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">222</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> Array[*(&quot;cab&quot;..&quot;cat&quot;).to_a]</span></code></div></div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
431
+ <div class="code"><pre>o = <span class="constant">Object</span>.new
432
+ <span class="keyword">def</span> o.<span class="function">==</span>(other); <span class="predefined-constant">true</span>; <span class="keyword">end</span>
433
+ o2 = <span class="constant">Object</span>.new
434
+ <span class="keyword">def</span> o2.<span class="function">==</span>(other); <span class="predefined-constant">true</span>; <span class="keyword">end</span>
435
+ </pre></div>
436
+ </div>
437
+ <div class="anchor" id="success223"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">223</span> <code class="inline">Array[1, o, o2, 2].<span class="bold">delete</span>(42) <span class="verification">==</span><span class="verification"> o2</span></code></div></div><div class="anchor" id="success224"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">224</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2]</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature39"><span class="anchor" id="public28"><span class="tag public">public</span></span> <span class="anchor" id="instance24"><span class="tag instance">24</span></span> Array#<span class="feature-name">delete_at</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">delete_at</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">#slice!</code></div><span class="head">Usage</span> <code class="inline">(index)</code> → Object | <code class="inline">nil</code><div class="p">Deletes the element at the specified <code class="inline">index</code>, returning that element, or <code class="inline">nil</code> if the index is out of range.</div><div class="CodeRay">
438
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">ant</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">bat</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">cat</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">dog</span><span class="delimiter">&quot;</span></span>]
439
+ a.delete_at(<span class="integer">2</span>) <span class="comment">#=&gt; &quot;cat&quot;</span>
440
+ a <span class="comment">#=&gt; [&quot;ant&quot;, &quot;bat&quot;, &quot;dog&quot;]</span>
441
+ a.delete_at(<span class="integer">99</span>) <span class="comment">#=&gt; nil</span>
442
+ </pre></div>
443
+ </div>
444
+ </div><div class="dev-item"><div class="p"><span class="head">Test 41.</span> ruby/test/ruby/test_array.rb:test_delete_at</div><div class="anchor" id="success225"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">225</span> <code class="inline">[1, 2, 3, 4, 5].<span class="bold">delete_at</span>(2) <span class="verification">==</span><span class="verification"> 3</span></code></div></div><div class="anchor" id="success226"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">226</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2, 4, 5]</span></code></div></div><div class="anchor" id="success227"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">227</span> <code class="inline">[1, 2, 3, 4, 5].<span class="bold">delete_at</span>(-2) <span class="verification">==</span><span class="verification"> 4</span></code></div></div><div class="anchor" id="success228"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">228</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2, 3, 5]</span></code></div></div><div class="anchor" id="success229"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">229</span> <code class="inline">[1, 2, 3, 4, 5].<span class="bold">delete_at</span>(5)<span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="anchor" id="success230"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">230</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2, 3, 4, 5]</span></code></div></div><div class="anchor" id="success231"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">231</span> <code class="inline">[1, 2, 3, 4, 5].<span class="bold">delete_at</span>(-6)<span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="anchor" id="success232"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">232</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2, 3, 4, 5]</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature40"><span class="anchor" id="public29"><span class="tag public">public</span></span> <span class="anchor" id="instance25"><span class="tag instance">25</span></span> Array#<span class="feature-name">delete_if</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">delete_if</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">#reject!</code></div><span class="head">Usage</span> <code class="inline">{|item| block}</code> → Array<div class="p">Deletes every element of <code class="inline">self</code> for which block evaluates to <code class="inline">true</code>.</div><div class="p">The array is changed instantly every time the block is called, not after the iteration is over.</div><span class="head">Usage</span> <code class="inline"></code> → Enumerator<div class="CodeRay">
445
+ <div class="code"><pre>scores = [<span class="integer">97</span>, <span class="integer">42</span>, <span class="integer">75</span>]
446
+ scores.delete_if{|score| score &lt; <span class="integer">80</span>} <span class="comment">#=&gt; [97]</span>
447
+ </pre></div>
448
+ </div>
449
+ </div><div class="dev-item"><div class="p"><span class="head">Test 42.</span> ruby/test/ruby/test_array.rb:test_delete_if</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
450
+ <div class="code"><pre>a = <span class="constant">Array</span>[<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>, <span class="integer">4</span>, <span class="integer">5</span>]</pre></div>
451
+ </div>
452
+ <div class="anchor" id="success233"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">233</span> <code class="inline">a.<span class="bold">delete_if</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:891)} <span class="verification">==</span><span class="verification"> a</span></code></div></div><div class="anchor" id="success234"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">234</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2, 3, 4, 5]</span></code></div></div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
453
+ <div class="code"><pre>a = <span class="constant">Array</span>[<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>, <span class="integer">4</span>, <span class="integer">5</span>]</pre></div>
454
+ </div>
455
+ <div class="anchor" id="success235"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">235</span> <code class="inline">a.<span class="bold">delete_if</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:894)} <span class="verification">==</span><span class="verification"> a</span></code></div></div><div class="anchor" id="success236"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">236</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
456
+ <div class="code"><pre>a = <span class="constant">Array</span>[<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>, <span class="integer">4</span>, <span class="integer">5</span>]</pre></div>
457
+ </div>
458
+ <div class="anchor" id="success237"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">237</span> <code class="inline">a.<span class="bold">delete_if</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:897)} <span class="verification">==</span><span class="verification"> a</span></code></div></div><div class="anchor" id="success238"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">238</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2, 3]</span></code></div></div><div class="p"><span class="head">Test 42.1.</span> bug2545 = ruby-core:27366</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
459
+ <div class="code"><pre>a = <span class="constant">Array</span>[<span class="integer">5</span>, <span class="integer">6</span>, <span class="integer">7</span>, <span class="integer">8</span>, <span class="integer">9</span>, <span class="integer">10</span>]</pre></div>
460
+ </div>
461
+ <div class="anchor" id="bug2"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">2</span> <code class="inline">a.<span class="bold">delete_if</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:901)} <span class="verification">==</span><span class="verification"> 9</span></code></div><ul><li><code class="inline">delete_if</code>: <span class="dev-text bug">LocalJumpError. Break from proc-closure.</span><table class="backtrace"><colgroup><col /><col /></colgroup><tbody><tr><td><code>spec:901</code></td><td><code class="inline"></code></td></tr></tbody></table></li></ul></div><div class="anchor" id="untestable1"><div class="indent dev-text untestable p"><span class="hang-indent">​</span><span class="tag untestable">1</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [7, 8, 9, 10]</span></code></div><div class="p indent"><span class="dev-text untestable">Missing a preceding successful unit test.</span></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature41"><span class="anchor" id="public30"><span class="tag public">public</span></span> <span class="anchor" id="instance26"><span class="tag instance">26</span></span> Array#<span class="feature-name">drop</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">drop</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">#take</code></div><span class="head">Usage</span> <code class="inline">(n)</code> → Array<div class="p">Drops first <code class="inline">n</code> elements from <code class="inline">ary</code> and returns the rest of the elements in an array.</div><div class="p">If a negative number is given, raises an <code class="inline">ArgumentError</code>.</div><div class="CodeRay">
462
+ <div class="code"><pre>a = [<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>, <span class="integer">4</span>, <span class="integer">5</span>, <span class="integer">0</span>]
463
+ a.drop(<span class="integer">3</span>) <span class="comment">#=&gt; [4, 5, 0]</span>
464
+ </pre></div>
465
+ </div>
466
+ </div><div class="dev-item"><div class="p"><span class="head">Test 43.</span> ruby/test/ruby/test_array.rb:test_drop</div><div class="anchor" id="success239"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">239</span> <code class="inline">[1, 2, 3, 4, 5, 0].<span class="bold">drop</span>(3) <span class="verification">==</span><span class="verification"> [4, 5, 0]</span></code></div></div><div class="p"><span class="head">Test 43.1.</span> ruby-dev:34123</div><div class="anchor" id="success240"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">240</span> <code class="inline">[1, 2].<span class="bold">drop</span>(-1)<span class="verification">.</span><span class="verification">raise?</span><span class="verification">(ArgumentError)</span></code></div></div><div class="p"><span class="head">Test 43.2.</span> ruby-dev:34123</div><div class="anchor" id="success241"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">241</span> <code class="inline">[1, 2].<span class="bold">drop</span>(1000000000) <span class="verification">==</span><span class="verification"> []</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature42"><span class="anchor" id="public31"><span class="tag public">public</span></span> <span class="anchor" id="instance27"><span class="tag instance">27</span></span> Array#<span class="feature-name">drop_while</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">drop_while</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">#take_while</code></div><span class="head">Usage</span> <code class="inline">{|arr| block}</code> → Array<div class="p">Drops elements up to, but not including, the first element for which the block returns <code class="inline">nil</code> or <code class="inline">false</code> and returns an array containing the remaining elements.</div><span class="head">Usage</span> <code class="inline"></code> → Enumerator<div class="CodeRay">
467
+ <div class="code"><pre>a = [<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>, <span class="integer">4</span>, <span class="integer">5</span>, <span class="integer">0</span>]
468
+ a.drop_while{|i| i &lt; <span class="integer">3</span>} <span class="comment">#=&gt; [3, 4, 5, 0]</span>
469
+ </pre></div>
470
+ </div>
471
+ </div><div class="dev-item"><div class="p indent anchor" id="missing_test5"><span class="hang-indent">​</span><span class="tag missing_test">Missing test</span><span class="dev-text missing_test"> Not unit tested.</span></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature43"><span class="anchor" id="public32"><span class="tag public">public</span></span> <span class="anchor" id="instance28"><span class="tag instance">28</span></span> Array#<span class="feature-name">each</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">each</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline">{|item| block}</code> → Array<div class="p">Calls the given block once for each element in <code class="inline">self</code>, passing that element as a parameter.</div><span class="head">Usage</span> <code class="inline"></code> → Enumerator<div class="CodeRay">
472
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>]
473
+ a.each{|x| print x, <span class="string"><span class="delimiter">&quot;</span><span class="content"> -- </span><span class="delimiter">&quot;</span></span>}
474
+ </pre></div>
475
+ </div>
476
+ <div class="p">produces:</div><div class="CodeRay">
477
+ <div class="code"><pre>a -- b -- c --
478
+ </pre></div>
479
+ </div>
480
+ </div><div class="dev-item"><div class="p indent anchor" id="missing_test6"><span class="hang-indent">​</span><span class="tag missing_test">Missing test</span><span class="dev-text missing_test"> Not unit tested.</span></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature44"><span class="anchor" id="public33"><span class="tag public">public</span></span> <span class="anchor" id="instance29"><span class="tag instance">29</span></span> Array#<span class="feature-name">each_index</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">each_index</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline">{|index| block}</code> → Array<div class="p">Same as <code class="inline">#each</code>, but passes the index of the element instead of the element itself.</div><span class="head">Usage</span> <code class="inline"></code> → Enumerator<div class="CodeRay">
481
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>]
482
+ a.each_index{|x| print x, <span class="string"><span class="delimiter">&quot;</span><span class="content"> -- </span><span class="delimiter">&quot;</span></span>}
483
+ </pre></div>
484
+ </div>
485
+ <div class="p">produces:</div><div class="CodeRay">
486
+ <div class="code"><pre><span class="integer">0</span> -- <span class="integer">1</span> -- <span class="integer">2</span> --
487
+ </pre></div>
488
+ </div>
489
+ </div><div class="dev-item"><div class="p indent anchor" id="missing_test7"><span class="hang-indent">​</span><span class="tag missing_test">Missing test</span><span class="dev-text missing_test"> Not unit tested.</span></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature45"><span class="anchor" id="public34"><span class="tag public">public</span></span> <span class="anchor" id="instance30"><span class="tag instance">30</span></span> Array#<span class="feature-name">empty?</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">empty?</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline"></code> → <code class="inline">true</code> | <code class="inline">false</code><div class="p">Returns <code class="inline">true</code> if <code class="inline">self</code> contains no elements.</div><div class="CodeRay">
490
+ <div class="code"><pre>[].empty? <span class="comment">#=&gt; true</span>
491
+ </pre></div>
492
+ </div>
493
+ </div><div class="dev-item"><div class="p"><span class="head">Test 44.</span> ruby/test/ruby/test_array.rb:test_empty_0</div><div class="anchor" id="success242"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">242</span> <code class="inline">[].<span class="bold">empty?</span> <span class="verification">==</span><span class="verification"> true</span></code></div></div><div class="anchor" id="success243"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">243</span> <code class="inline">[1].<span class="bold">empty?</span> <span class="verification">==</span><span class="verification"> false</span></code></div></div><div class="anchor" id="success244"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">244</span> <code class="inline">[1, 1, 4, 2, 5, 4, 5, 1, 2].<span class="bold">empty?</span> <span class="verification">==</span><span class="verification"> false</span></code></div></div><div class="p"><span class="head">Test 45.</span> ruby/test/ruby/test_array.rb:test_empty?</div><div class="anchor" id="success245"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">245</span> <code class="inline">[].<span class="bold">empty?</span> <span class="verification">==</span><span class="verification"> true</span></code></div></div><div class="anchor" id="success246"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">246</span> <code class="inline">[1].<span class="bold">empty?</span> <span class="verification">==</span><span class="verification"> false</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature46"><span class="anchor" id="public35"><span class="tag public">public</span></span> <span class="anchor" id="instance31"><span class="tag instance">31</span></span> Array#<span class="feature-name">eql?</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">eql?</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline">(other)</code> → <code class="inline">true</code> | <code class="inline">false</code><div class="p">Returns <code class="inline">true</code> if <code class="inline">self</code> and other are the same object, or are both arrays with the same content (according to <code class="inline">Object#eql?</code>).</div></div><div class="dev-item"><div class="p"><span class="head">Test 46.</span> ruby/test/ruby/test_array.rb:test_eql?</div><div class="anchor" id="success247"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">247</span> <code class="inline">[].<span class="bold">eql?</span>([]) <span class="verification">==</span><span class="verification"> true</span></code></div></div><div class="anchor" id="success248"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">248</span> <code class="inline">[1].<span class="bold">eql?</span>([1]) <span class="verification">==</span><span class="verification"> true</span></code></div></div><div class="anchor" id="success249"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">249</span> <code class="inline">[1, 1, 2, 2].<span class="bold">eql?</span>([1, 1, 2, 2]) <span class="verification">==</span><span class="verification"> true</span></code></div></div><div class="anchor" id="success250"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">250</span> <code class="inline">[1, 1, 2, 2].<span class="bold">eql?</span>([1.0, 1.0, 2.0, 2.0]) <span class="verification">==</span><span class="verification"> false</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature47"><span class="anchor" id="public36"><span class="tag public">public</span></span> <span class="anchor" id="instance32"><span class="tag instance">32</span></span> Array#<span class="feature-name">fetch</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">fetch</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline">(index)</code> → Object<div class="p">Tries to return the element at position <code class="inline">index</code>, but throws an <code class="inline">IndexError</code> exception if the referenced <code class="inline">index</code> lies outside of the array bounds.</div><span class="head">Usage</span> <code class="inline">(index, default)</code> → Object<div class="p">This error is prevented by the <code class="inline">default</code>, which will act as a default value.</div><span class="head">Usage</span> <code class="inline">(index){|index| block}</code> → Object<div class="p">It will only be executed when an invalid index is referenced. Negative values of index count from the end of the array.</div><div class="CodeRay">
494
+ <div class="code"><pre>a = [<span class="integer">11</span>, <span class="integer">22</span>, <span class="integer">33</span>, <span class="integer">44</span>]
495
+ a.fetch(<span class="integer">1</span>) <span class="comment">#=&gt; 22</span>
496
+ a.fetch(<span class="integer">-1</span>) <span class="comment">#=&gt; 44</span>
497
+ a.fetch(<span class="integer">4</span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">cat</span><span class="delimiter">&quot;</span></span>) <span class="comment">#=&gt; &quot;cat&quot;</span>
498
+ a.fetch(<span class="integer">100</span>){|i| puts <span class="string"><span class="delimiter">&quot;</span><span class="char">\#</span><span class="char">\{</span><span class="content">i</span><span class="char">\}</span><span class="content"> is out of bounds</span><span class="delimiter">&quot;</span></span>}
499
+ <span class="comment">#=&gt; &quot;100 is out of bounds&quot;</span>
500
+ </pre></div>
501
+ </div>
502
+ </div><div class="dev-item"><div class="p"><span class="head">Test 47.</span> ruby/test/ruby/test_array.rb:test_fetch</div><div class="anchor" id="success251"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">251</span> <code class="inline">[].<span class="bold">fetch</span>(0, 0){(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:995)} <span class="verification">==</span><span class="verification"> 1</span></code></div></div><div class="anchor" id="success252"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">252</span> <code class="inline">[0, 1].<span class="bold">fetch</span>(-1) <span class="verification">==</span><span class="verification"> 1</span></code></div></div><div class="anchor" id="success253"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">253</span> <code class="inline">[0, 1].<span class="bold">fetch</span>(2)<span class="verification">.</span><span class="verification">raise?</span><span class="verification">(IndexError)</span></code></div></div><div class="anchor" id="success254"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">254</span> <code class="inline">[0, 1].<span class="bold">fetch</span>(-3)<span class="verification">.</span><span class="verification">raise?</span><span class="verification">(IndexError)</span></code></div></div><div class="anchor" id="success255"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">255</span> <code class="inline">[0, 1].<span class="bold">fetch</span>(2, 2) <span class="verification">==</span><span class="verification"> 2</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature48"><span class="anchor" id="public37"><span class="tag public">public</span></span> <span class="anchor" id="instance33"><span class="tag instance">33</span></span> Array#<span class="feature-name">fill</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">fill</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline">(obj)</code> → Array<span class="head">Usage</span> <code class="inline">(obj, start [, length])</code> → Array<span class="head">Usage</span> <code class="inline">(obj, range)</code> → Array<div class="p">Sets the selected elements of <code class="inline">self</code> (which may be the entire array) to <code class="inline">obj</code>.</div><div class="p">A <code class="inline">start</code> of <code class="inline">nil</code> is equivalent to zero.</div><div class="p">A <code class="inline">length</code> of <code class="inline">nil</code> is equivalent to the length of the array.</div><div class="p">Negative values of <code class="inline">start</code> count from the end of the array, where <code class="inline">-1</code> is the last element.</div><span class="head">Usage</span> <code class="inline">{|index| block}</code> → Array<span class="head">Usage</span> <code class="inline">(start [, length]){|index| block}</code> → Array<span class="head">Usage</span> <code class="inline">(range){|index| block}</code> → Array<div class="p">Fills the array with the value of the given block, which is passed the absolute index of each element to be filled.</div><div class="CodeRay">
503
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">d</span><span class="delimiter">&quot;</span></span>]
504
+ a.fill(<span class="string"><span class="delimiter">&quot;</span><span class="content">x</span><span class="delimiter">&quot;</span></span>) <span class="comment">#=&gt; [&quot;x&quot;, &quot;x&quot;, &quot;x&quot;, &quot;x&quot;]</span>
505
+ a.fill(<span class="string"><span class="delimiter">&quot;</span><span class="content">z</span><span class="delimiter">&quot;</span></span>, <span class="integer">2</span>, <span class="integer">2</span>) <span class="comment">#=&gt; [&quot;x&quot;, &quot;x&quot;, &quot;z&quot;, &quot;z&quot;]</span>
506
+ a.fill(<span class="string"><span class="delimiter">&quot;</span><span class="content">y</span><span class="delimiter">&quot;</span></span>, <span class="integer">0</span>..<span class="integer">1</span>) <span class="comment">#=&gt; [&quot;y&quot;, &quot;y&quot;, &quot;z&quot;, &quot;z&quot;]</span>
507
+ a.fill{|i| i*i} <span class="comment">#=&gt; [0, 1, 4, 9]</span>
508
+ a.fill(<span class="integer">-2</span>){|i| i*i*i} <span class="comment">#=&gt; [0, 1, 8, 27]</span>
509
+ </pre></div>
510
+ </div>
511
+ </div><div class="dev-item"><div class="p"><span class="head">Test 48.</span> ruby/test/ruby/test_array.rb:test_fill</div><div class="anchor" id="success256"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">256</span> <code class="inline">[].<span class="bold">fill</span>(99) <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="anchor" id="success257"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">257</span> <code class="inline">[].<span class="bold">fill</span>(99, 0) <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="anchor" id="success258"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">258</span> <code class="inline">[].<span class="bold">fill</span>(99, 0, 1) <span class="verification">==</span><span class="verification"> [99]</span></code></div></div><div class="anchor" id="success259"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">259</span> <code class="inline">[].<span class="bold">fill</span>(99, 0..0) <span class="verification">==</span><span class="verification"> [99]</span></code></div></div><div class="anchor" id="success260"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">260</span> <code class="inline">[1].<span class="bold">fill</span>(99) <span class="verification">==</span><span class="verification"> [99]</span></code></div></div><div class="anchor" id="success261"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">261</span> <code class="inline">[1].<span class="bold">fill</span>(99, 0) <span class="verification">==</span><span class="verification"> [99]</span></code></div></div><div class="anchor" id="success262"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">262</span> <code class="inline">[1].<span class="bold">fill</span>(99, 0, 1) <span class="verification">==</span><span class="verification"> [99]</span></code></div></div><div class="anchor" id="success263"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">263</span> <code class="inline">[1].<span class="bold">fill</span>(99, 0..0) <span class="verification">==</span><span class="verification"> [99]</span></code></div></div><div class="anchor" id="success264"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">264</span> <code class="inline">[1, 2].<span class="bold">fill</span>(99) <span class="verification">==</span><span class="verification"> [99, 99]</span></code></div></div><div class="anchor" id="success265"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">265</span> <code class="inline">[1, 2].<span class="bold">fill</span>(99, 0) <span class="verification">==</span><span class="verification"> [99, 99]</span></code></div></div><div class="anchor" id="success266"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">266</span> <code class="inline">[1, 2].<span class="bold">fill</span>(99, nil) <span class="verification">==</span><span class="verification"> [99, 99]</span></code></div></div><div class="anchor" id="success267"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">267</span> <code class="inline">[1, 2].<span class="bold">fill</span>(99, 1, nil) <span class="verification">==</span><span class="verification"> [1, 99]</span></code></div></div><div class="anchor" id="success268"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">268</span> <code class="inline">[1, 2].<span class="bold">fill</span>(99, 0, 1) <span class="verification">==</span><span class="verification"> [99, 2]</span></code></div></div><div class="anchor" id="success269"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">269</span> <code class="inline">[1, 2].<span class="bold">fill</span>(99, 0..0) <span class="verification">==</span><span class="verification"> [99, 2]</span></code></div></div><div class="p"><span class="head">Test 49.</span> ruby/test/ruby/test_array.rb:test_fill_0</div><div class="anchor" id="success270"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">270</span> <code class="inline">[0, 1, 2, 3, 4, 5].<span class="bold">fill</span>(-1) <span class="verification">==</span><span class="verification"> [-1, -1, -1, -1, -1, -1]</span></code></div></div><div class="anchor" id="success271"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">271</span> <code class="inline">[0, 1, 2, 3, 4, 5].<span class="bold">fill</span>(-1, 3) <span class="verification">==</span><span class="verification"> [0, 1, 2, -1, -1, -1]</span></code></div></div><div class="anchor" id="success272"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">272</span> <code class="inline">[0, 1, 2, 3, 4, 5].<span class="bold">fill</span>(-1, 3, 2) <span class="verification">==</span><span class="verification"> [0, 1, 2, -1, -1, 5]</span></code></div></div><div class="anchor" id="success273"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">273</span> <code class="inline">[0, 1, 2, 3, 4, 5].<span class="bold">fill</span>(-1, 3, 5) <span class="verification">==</span><span class="verification"> [0, 1, 2, -1, -1, -1, -1, -1]</span></code></div></div><div class="anchor" id="success274"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">274</span> <code class="inline">[0, 1, 2, 3, 4, 5].<span class="bold">fill</span>(-1, 2, 2) <span class="verification">==</span><span class="verification"> [0, 1, -1, -1, 4, 5]</span></code></div></div><div class="anchor" id="success275"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">275</span> <code class="inline">[0, 1, 2, 3, 4, 5].<span class="bold">fill</span>(-1, 2, 5) <span class="verification">==</span><span class="verification"> [0, 1, -1, -1, -1, -1, -1]</span></code></div></div><div class="anchor" id="success276"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">276</span> <code class="inline">[0, 1, 2, 3, 4, 5].<span class="bold">fill</span>(-1, -2, 1) <span class="verification">==</span><span class="verification"> [0, 1, 2, 3, -1, 5]</span></code></div></div><div class="anchor" id="success277"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">277</span> <code class="inline">[0, 1, 2, 3, 4, 5].<span class="bold">fill</span>(-1, -2, 3) <span class="verification">==</span><span class="verification"> [0, 1, 2, 3, -1, -1, -1]</span></code></div></div><div class="anchor" id="success278"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">278</span> <code class="inline">[0, 1, 2, 3, 4, 5].<span class="bold">fill</span>(-1, 3..4) <span class="verification">==</span><span class="verification"> [0, 1, 2, -1, -1, 5]</span></code></div></div><div class="anchor" id="success279"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">279</span> <code class="inline">[0, 1, 2, 3, 4, 5].<span class="bold">fill</span>(-1, 3...4) <span class="verification">==</span><span class="verification"> [0, 1, 2, -1, 4, 5]</span></code></div></div><div class="anchor" id="success280"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">280</span> <code class="inline">[0, 1, 2, 3, 4, 5].<span class="bold">fill</span>(-1, 2..-2) <span class="verification">==</span><span class="verification"> [0, 1, -1, -1, -1, 5]</span></code></div></div><div class="anchor" id="success281"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">281</span> <code class="inline">[0, 1, 2, 3, 4, 5].<span class="bold">fill</span>(-1, 2...-2) <span class="verification">==</span><span class="verification"> [0, 1, -1, -1, 4, 5]</span></code></div></div><div class="anchor" id="success282"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">282</span> <code class="inline">[0, 1, 2, 3, 4, 5].<span class="bold">fill</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:1049)} <span class="verification">==</span><span class="verification"> [10, 11, 12, 13, 14, 15]</span></code></div></div><div class="anchor" id="success283"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">283</span> <code class="inline">[0, 1, 2, 3, 4, 5].<span class="bold">fill</span>(3){(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:1050)} <span class="verification">==</span><span class="verification"> [0, 1, 2, 13, 14, 15]</span></code></div></div><div class="anchor" id="success284"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">284</span> <code class="inline">[0, 1, 2, 3, 4, 5].<span class="bold">fill</span>(3, 2){(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:1051)} <span class="verification">==</span><span class="verification"> [0, 1, 2, 13, 14, 5]</span></code></div></div><div class="anchor" id="success285"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">285</span> <code class="inline">[0, 1, 2, 3, 4, 5].<span class="bold">fill</span>(3, 5){(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:1052)} <span class="verification">==</span><span class="verification"> [0, 1, 2, 13, 14, 15, 16, 17]</span></code></div></div><div class="anchor" id="success286"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">286</span> <code class="inline">[0, 1, 2, 3, 4, 5].<span class="bold">fill</span>(3..4){(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:1053)} <span class="verification">==</span><span class="verification"> [0, 1, 2, 13, 14, 5]</span></code></div></div><div class="anchor" id="success287"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">287</span> <code class="inline">[0, 1, 2, 3, 4, 5].<span class="bold">fill</span>(3...4){(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:1054)} <span class="verification">==</span><span class="verification"> [0, 1, 2, 13, 4, 5]</span></code></div></div><div class="anchor" id="success288"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">288</span> <code class="inline">[0, 1, 2, 3, 4, 5].<span class="bold">fill</span>(2..-2){(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:1055)} <span class="verification">==</span><span class="verification"> [0, 1, 12, 13, 14, 5]</span></code></div></div><div class="anchor" id="success289"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">289</span> <code class="inline">[0, 1, 2, 3, 4, 5].<span class="bold">fill</span>(2...-2){(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:1056)} <span class="verification">==</span><span class="verification"> [0, 1, 12, 13, 4, 5]</span></code></div></div><div class="p"><span class="head">Test 50.</span> ruby/test/ruby/test_array.rb:test_fill2</div><div class="anchor" id="success290"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">290</span> <code class="inline">[].<span class="bold">fill</span>(0, 1, longp)<span class="verification">.</span><span class="verification">raise?</span><span class="verification">(ArgumentError)</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature49"><span class="anchor" id="public38"><span class="tag public">public</span></span> <span class="anchor" id="instance34"><span class="tag instance">34</span></span> Array#<span class="feature-name">find_index</span> (alias: <span class="feature-name">index</span>)</h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">find_index</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">#rindex</code>.</div><span class="head">Usage</span> <code class="inline">(obj)</code> → Integer | <code class="inline">nil</code><div class="p">Returns the index of the first object in <code class="inline">ary</code> such that the object is <code class="inline">==</code> to <code class="inline">obj</code>. Returns <code class="inline">nil</code> if no match is found.</div><span class="head">Usage</span> <code class="inline">{|item| block}</code> → Integer | <code class="inline">nil</code><div class="p">Returns the index of the first object for which the block returns <code class="inline">true</code>. Returns <code class="inline">nil</code> if no match is found.</div><span class="head">Usage</span> <code class="inline"></code> → Enumerator<div class="CodeRay">
512
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>]
513
+ a.index(<span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>) <span class="comment">#=&gt; 1</span>
514
+ a.index(<span class="string"><span class="delimiter">&quot;</span><span class="content">z</span><span class="delimiter">&quot;</span></span>) <span class="comment">#=&gt; nil</span>
515
+ a.index{|x| x == <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>} <span class="comment">#=&gt; 1</span>
516
+ </pre></div>
517
+ </div>
518
+ </div><div class="dev-item"><div class="p indent anchor" id="missing_test8"><span class="hang-indent">​</span><span class="tag missing_test">Missing test</span><span class="dev-text missing_test"> Not unit tested.</span></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature50"><span class="anchor" id="public39"><span class="tag public">public</span></span> <span class="anchor" id="instance35"><span class="tag instance">35</span></span> Array#<span class="feature-name">first</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">first</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">#last</code> for the opposite effect.</div><span class="head">Usage</span> <code class="inline">first</code> → Object | <code class="inline">nil</code><div class="p">Returns the first element of the array. If the array is empty, returns <code class="inline">nil</code>.</div><span class="head">Usage</span> <code class="inline">(n)</code> → Array<div class="p">Returns the first <code class="inline">n</code> elements of the array. If the array is empty, returns an empty array.</div><div class="CodeRay">
519
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">q</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">r</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">s</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">t</span><span class="delimiter">&quot;</span></span>]
520
+ a.first <span class="comment">#=&gt; &quot;q&quot;</span>
521
+ a.first(<span class="integer">2</span>) <span class="comment">#=&gt; [&quot;q&quot;, &quot;r&quot;]</span>
522
+ </pre></div>
523
+ </div>
524
+ </div><div class="dev-item"><div class="p"><span class="head">Test 51.</span> ruby/test/ruby/test_array.rb:test_first</div><div class="anchor" id="success291"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">291</span> <code class="inline">[3, 4, 5].<span class="bold">first</span> <span class="verification">==</span><span class="verification"> 3</span></code></div></div><div class="anchor" id="success292"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">292</span> <code class="inline">[].<span class="bold">first</span><span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="p"><span class="head">Test 52.</span> ruby/test/ruby/test_array.rb:test_first2</div><div class="anchor" id="success293"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">293</span> <code class="inline">[0].<span class="bold">first</span>(2) <span class="verification">==</span><span class="verification"> [0]</span></code></div></div><div class="anchor" id="success294"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">294</span> <code class="inline">[0].<span class="bold">first</span>(-1)<span class="verification">.</span><span class="verification">raise?</span><span class="verification">(ArgumentError)</span></code></div></div><div class="p"><span class="head">Test 53.</span> ruby/test/ruby/test_array.rb:test_beg_end_0:1/6</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
525
+ <div class="code"><pre>x = [<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>, <span class="integer">4</span>, <span class="integer">5</span>]</pre></div>
526
+ </div>
527
+ <div class="anchor" id="success295"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">295</span> <code class="inline">x.<span class="bold">first</span> <span class="verification">==</span><span class="verification"> 1</span></code></div></div><div class="anchor" id="success296"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">296</span> <code class="inline">x.<span class="bold">first</span>(1) <span class="verification">==</span><span class="verification"> [1]</span></code></div></div><div class="anchor" id="success297"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">297</span> <code class="inline">x.<span class="bold">first</span>(3) <span class="verification">==</span><span class="verification"> [1, 2, 3]</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature51"><span class="anchor" id="public40"><span class="tag public">public</span></span> <span class="anchor" id="instance36"><span class="tag instance">36</span></span> Array#<span class="feature-name">flatten</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">flatten</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline"></code> → Array<div class="p">Returns a new array that is a one-dimensional flattening of <code class="inline">self</code> (recursively). That is, for every element that is an array, extract its elements into the new array.</div><span class="head">Usage</span> <code class="inline">(level)</code> → Array<div class="p">The optional <code class="inline">level</code> argument determines the level of recursion to flatten.</div><div class="CodeRay">
528
+ <div class="code"><pre>s = [<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>] <span class="comment">#=&gt; [1, 2, 3]</span>
529
+ t = [<span class="integer">4</span>, <span class="integer">5</span>, <span class="integer">6</span>, [<span class="integer">7</span>, <span class="integer">8</span>]] <span class="comment">#=&gt; [4, 5, 6, [7, 8]]</span>
530
+ a = [s, t, <span class="integer">9</span>, <span class="integer">10</span>] <span class="comment">#=&gt; [[1, 2, 3], [4, 5, 6, [7, 8]], 9, 10]</span>
531
+ a.flatten <span class="comment">#=&gt; [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]</span>
532
+ a = [<span class="integer">1</span>, <span class="integer">2</span>, [<span class="integer">3</span>, [<span class="integer">4</span>, <span class="integer">5</span>]]]
533
+ a.flatten(<span class="integer">1</span>) <span class="comment">#=&gt; [1, 2, 3, [4, 5]]</span>
534
+ </pre></div>
535
+ </div>
536
+ </div><div class="dev-item"><div class="p"><span class="head">Test 54.</span> ruby/test/ruby/test_array.rb:test_flatten</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
537
+ <div class="code"><pre>a1 = <span class="constant">Array</span>[<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>]
538
+ a3 = <span class="constant">Array</span>[<span class="integer">4</span>, <span class="constant">Array</span>[<span class="integer">5</span>, <span class="integer">6</span>]]
539
+ </pre></div>
540
+ </div>
541
+ <div class="anchor" id="success298"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">298</span> <code class="inline">Array[a1, a3].<span class="bold">flatten</span> <span class="verification">==</span><span class="verification"> [1, 2, 3, 4, 5, 6]</span></code></div></div><div class="anchor" id="success299"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">299</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> Array[a1, a3]</span></code></div></div><div class="anchor" id="success300"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">300</span> <code class="inline">Array[a1, Array[], a3].<span class="bold">flatten</span> <span class="verification">==</span><span class="verification"> [1, 2, 3, 4, 5, 6]</span></code></div></div><div class="anchor" id="success301"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">301</span> <code class="inline">[].<span class="bold">flatten</span> <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="anchor" id="success302"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">302</span> <code class="inline">[[[[], []], [[]], []], [[[]]]].<span class="bold">flatten</span> <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="p"><span class="head">Test 54.1.</span> ruby-dev:31197</div><div class="anchor" id="success303"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">303</span> <code class="inline">[[]].<span class="bold">flatten</span>(&quot;&quot;)<span class="verification">.</span><span class="verification">raise?</span><span class="verification">(TypeError)</span></code></div></div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
542
+ <div class="code"><pre>a6 = <span class="constant">Array</span>[[<span class="integer">1</span>, <span class="integer">2</span>], <span class="integer">3</span>]
543
+ a6.taint
544
+ a8 = <span class="constant">Array</span>[[<span class="integer">1</span>, <span class="integer">2</span>], <span class="integer">3</span>]
545
+ </pre></div>
546
+ </div>
547
+ <div class="anchor" id="success304"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">304</span> <code class="inline">a6.<span class="bold">flatten</span><span class="verification">.</span><span class="verification">tainted?</span><span class="verification"></span></code></div></div><div class="anchor" id="success305"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">305</span> <code class="inline">a8.<span class="bold">flatten</span>(0) <span class="verification">==</span><span class="verification"> a8</span></code></div></div><div class="anchor" id="success306"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">306</span> <code class="inline">RETURN<span class="verification">.</span><span class="verification">equal?</span><span class="verification">(a8)</span><span class="verification">.</span><span class="verification">!</span><span class="verification"></span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature52"><span class="anchor" id="public41"><span class="tag public">public</span></span> <span class="anchor" id="instance37"><span class="tag instance">37</span></span> Array#<span class="feature-name">flatten!</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">flatten!</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline"></code> → Array | <code class="inline">nil</code><div class="p">Flattens <code class="inline">self</code> in place. Returns <code class="inline">nil</code> if no modifications were made (i.e., the array contains no subarrays.</div><span class="head">Usage</span> <code class="inline">(level)</code> → Array | <code class="inline">nil</code><div class="p">The optional <code class="inline">level</code> argument determines the level of recursion to flatten.</div><div class="CodeRay">
548
+ <div class="code"><pre>a = [<span class="integer">1</span>, <span class="integer">2</span>, [<span class="integer">3</span>, [<span class="integer">4</span>, <span class="integer">5</span>]]]
549
+ a.flatten! <span class="comment">#=&gt; [1, 2, 3, 4, 5]</span>
550
+ a.flatten! <span class="comment">#=&gt; nil</span>
551
+ a <span class="comment">#=&gt; [1, 2, 3, 4, 5]</span>
552
+ a = [<span class="integer">1</span>, <span class="integer">2</span>, [<span class="integer">3</span>, [<span class="integer">4</span>, <span class="integer">5</span>]]]
553
+ a.flatten!(<span class="integer">1</span>) <span class="comment">#=&gt; [1, 2, 3, [4, 5]]</span>
554
+ </pre></div>
555
+ </div>
556
+ </div><div class="dev-item"><div class="p"><span class="head">Test 55.</span> ruby/test/ruby/test_array.rb:test_flatten!</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
557
+ <div class="code"><pre>a1 = <span class="constant">Array</span>[<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>]
558
+ a3 = <span class="constant">Array</span>[<span class="integer">4</span>, <span class="constant">Array</span>[<span class="integer">5</span>, <span class="integer">6</span>]]
559
+ a5 = <span class="constant">Array</span>[a1, <span class="constant">Array</span>[], a3]
560
+ </pre></div>
561
+ </div>
562
+ <div class="anchor" id="success307"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">307</span> <code class="inline">Array[a1, a3].<span class="bold">flatten!</span> <span class="verification">==</span><span class="verification"> [1, 2, 3, 4, 5, 6]</span></code></div></div><div class="anchor" id="success308"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">308</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2, 3, 4, 5, 6]</span></code></div></div><div class="p"><span class="head">Test 55.1.</span> ruby-core:23382</div><div class="anchor" id="success309"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">309</span> <code class="inline">a5.<span class="bold">flatten!</span> <span class="verification">==</span><span class="verification"> [1, 2, 3, 4, 5, 6]</span></code></div></div><div class="anchor" id="success310"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">310</span> <code class="inline">a5.<span class="bold">flatten!</span>(0)<span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="anchor" id="bug3"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">3</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2, 3, 4, 5, 6]</span></code></div><ul><li><code class="inline">flatten!</code>: <span class="dev-text bug">The receiver of verification <code class="inline">==</code> is <code class="inline">[[1, 2, 3], [], [4, [5, 6]]]</code>.</span></li></ul></div><div class="anchor" id="success311"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">311</span> <code class="inline">[].<span class="bold">flatten!</span><span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="anchor" id="success312"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">312</span> <code class="inline">[[[[], []], [[]], []], [[[]]]].<span class="bold">flatten!</span> <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="p"><span class="head">Test 55.2.</span> ruby-core:23382</div><div class="anchor" id="success313"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">313</span> <code class="inline">[].<span class="bold">flatten!</span>(0)<span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature53"><span class="anchor" id="public42"><span class="tag public">public</span></span> <span class="anchor" id="instance38"><span class="tag instance">38</span></span> Array#<span class="feature-name">frozen?</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">frozen?</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">Object#frozen?</code></div><span class="head">Usage</span> <code class="inline"></code> → <code class="inline">true</code> | <code class="inline">false</code><div class="p">Returns <code class="inline">true</code> if this array is frozen (or temporarily frozen while being sorted).</div></div><div class="dev-item"><div class="p indent anchor" id="missing_test9"><span class="hang-indent">​</span><span class="tag missing_test">Missing test</span><span class="dev-text missing_test"> Not unit tested.</span></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature54"><span class="anchor" id="public43"><span class="tag public">public</span></span> <span class="anchor" id="instance39"><span class="tag instance">39</span></span> Array#<span class="feature-name">hash</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">hash</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline"></code> → Fixnum<div class="p">Computes a hash-code for this array. Two arrays with the same content will have the same hash code (and will compare using <code class="inline">eql?</code>).</div></div><div class="dev-item"><div class="p"><span class="head">Test 56.</span> ruby/test/ruby/test_array.rb:test_hash</div><div class="anchor" id="success314"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">314</span> <code class="inline">[&quot;cat&quot;, &quot;dog&quot;].<span class="bold">hash</span> <span class="verification">==</span><span class="verification"> Array[&quot;cat&quot;, &quot;dog&quot;].hash</span></code></div></div><div class="anchor" id="bug4"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">4</span> <code class="inline">[&quot;dog&quot;, &quot;cat&quot;].<span class="bold">hash</span> <span class="verification">==</span><span class="verification"> Array[&quot;cat&quot;, &quot;dog&quot;].hash</span></code></div><ul><li><code class="inline">hash</code>: <span class="dev-text bug">The receiver of verification <code class="inline">==</code> is <code class="inline">-67794575767490625</code>.</span></li></ul></div><div class="p"><span class="head">Test 56.1.</span> bug9231 = ruby-core:58993 Bug #9231</div><div class="anchor" id="success315"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">315</span> <code class="inline">[].<span class="bold">hash</span> <span class="verification">!=</span><span class="verification"> false.hash</span></code></div></div><div class="p"><span class="head">Test 57.</span> ruby/test/ruby/test_array.rb:test_0_literal:3/8</div><div class="anchor" id="success316"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">316</span> <code class="inline">[1, 2].<span class="bold">hash</span> <span class="verification">==</span><span class="verification"> [1, 2].hash</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature55"><span class="anchor" id="public44"><span class="tag public">public</span></span> <span class="anchor" id="instance40"><span class="tag instance">40</span></span> Array#<span class="feature-name">include?</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">include?</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline">(object)</code> → <code class="inline">true</code> | <code class="inline">false</code><div class="p">Returns <code class="inline">true</code> if the given object is present in <code class="inline">self</code> (that is, if any element <code class="inline">==</code> <code class="inline">object</code>), otherwise returns <code class="inline">false</code>.</div><div class="CodeRay">
563
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>]
564
+ a.include?(<span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>) <span class="comment">#=&gt; true</span>
565
+ a.include?(<span class="string"><span class="delimiter">&quot;</span><span class="content">z</span><span class="delimiter">&quot;</span></span>) <span class="comment">#=&gt; false</span>
566
+ </pre></div>
567
+ </div>
568
+ </div><div class="dev-item"><div class="p"><span class="head">Test 58.</span> ruby/test/ruby/test_array.rb:test_include?</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
569
+ <div class="code"><pre>a = <span class="constant">Array</span>[<span class="string"><span class="delimiter">&quot;</span><span class="content">cat</span><span class="delimiter">&quot;</span></span>, <span class="integer">99</span>, <span class="regexp"><span class="delimiter">/</span><span class="content">a</span><span class="delimiter">/</span></span>, <span class="constant">Array</span>[<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>]]</pre></div>
570
+ </div>
571
+ <div class="anchor" id="success317"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">317</span> <code class="inline">a.<span class="bold">include?</span>(&quot;cat&quot;) <span class="verification">==</span><span class="verification"> true</span></code></div></div><div class="anchor" id="success318"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">318</span> <code class="inline">a.<span class="bold">include?</span>(99) <span class="verification">==</span><span class="verification"> true</span></code></div></div><div class="anchor" id="success319"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">319</span> <code class="inline">a.<span class="bold">include?</span>(/a/) <span class="verification">==</span><span class="verification"> true</span></code></div></div><div class="anchor" id="success320"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">320</span> <code class="inline">a.<span class="bold">include?</span>([1, 2, 3]) <span class="verification">==</span><span class="verification"> true</span></code></div></div><div class="anchor" id="success321"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">321</span> <code class="inline">a.<span class="bold">include?</span>(&quot;ca&quot;) <span class="verification">==</span><span class="verification"> false</span></code></div></div><div class="anchor" id="success322"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">322</span> <code class="inline">a.<span class="bold">include?</span>([1, 2]) <span class="verification">==</span><span class="verification"> false</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature56"><span class="anchor" id="public45"><span class="tag public">public</span></span> <span class="anchor" id="instance41"><span class="tag instance">41</span></span> Array#<span class="feature-name">index</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">index</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">#rindex</code>.</div><span class="head">Usage</span> <code class="inline">(obj)</code> → Integer | <code class="inline">nil</code><div class="p">Returns the index of the first object in <code class="inline">self</code> such that the object is <code class="inline">==</code> to <code class="inline">obj</code>.</div><span class="head">Usage</span> <code class="inline">{|item| block}</code> → Integer | <code class="inline">nil</code><div class="p">Returns the index of the first object for which the block returns <code class="inline">true</code>. Returns <code class="inline">nil</code> if no match is found.</div><span class="head">Usage</span> <code class="inline">index</code> → Enumerator<div class="CodeRay">
572
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>]
573
+ a.index(<span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>) <span class="comment">#=&gt; 1</span>
574
+ a.index(<span class="string"><span class="delimiter">&quot;</span><span class="content">z</span><span class="delimiter">&quot;</span></span>) <span class="comment">#=&gt; nil</span>
575
+ a.index{|x| x == <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>} <span class="comment">#=&gt; 1</span>
576
+ </pre></div>
577
+ </div>
578
+ </div><div class="dev-item"><div class="p"><span class="head">Test 59.</span> ruby/test/ruby/test_array.rb:test_index</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
579
+ <div class="code"><pre>a = <span class="constant">Array</span>[<span class="string"><span class="delimiter">&quot;</span><span class="content">cat</span><span class="delimiter">&quot;</span></span>, <span class="integer">99</span>, <span class="regexp"><span class="delimiter">/</span><span class="content">a</span><span class="delimiter">/</span></span>, <span class="integer">99</span>, <span class="constant">Array</span>[<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>]]</pre></div>
580
+ </div>
581
+ <div class="anchor" id="success323"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">323</span> <code class="inline">a.<span class="bold">index</span>(&quot;cat&quot;)<span class="verification">.</span><span class="verification">zero?</span><span class="verification"></span></code></div></div><div class="anchor" id="success324"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">324</span> <code class="inline">a.<span class="bold">index</span>(99) <span class="verification">==</span><span class="verification"> 1</span></code></div></div><div class="anchor" id="success325"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">325</span> <code class="inline">a.<span class="bold">index</span>([1, 2, 3]) <span class="verification">==</span><span class="verification"> 4</span></code></div></div><div class="anchor" id="success326"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">326</span> <code class="inline">a.<span class="bold">index</span>(&quot;ca&quot;)<span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="anchor" id="success327"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">327</span> <code class="inline">a.<span class="bold">index</span>([1, 2])<span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="anchor" id="success328"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">328</span> <code class="inline">a.<span class="bold">index</span>(99){(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:1216)} <span class="verification">==</span><span class="verification"> 1</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature57"><span class="anchor" id="private1"><span class="tag private">private</span></span> <span class="anchor" id="instance42"><span class="tag instance">42</span></span> Array#<span class="feature-name">initialize_copy</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">initialize_copy</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline">(other_ary)</code> → Array<div class="p">Replaces the contents of <code class="inline">self</code> with the contents of <code class="inline">other_ary</code>, truncating or expanding if necessary.</div><div class="CodeRay">
582
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">d</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">e</span><span class="delimiter">&quot;</span></span>]
583
+ a.replace([<span class="string"><span class="delimiter">&quot;</span><span class="content">x</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">y</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">z</span><span class="delimiter">&quot;</span></span>]) <span class="comment">#=&gt; [&quot;x&quot;, &quot;y&quot;, &quot;z&quot;]</span>
584
+ a <span class="comment">#=&gt; [&quot;x&quot;, &quot;y&quot;, &quot;z&quot;]</span>
585
+ </pre></div>
586
+ </div>
587
+ </div><div class="dev-item"><div class="p indent anchor" id="missing_test10"><span class="hang-indent">​</span><span class="tag missing_test">Missing test</span><span class="dev-text missing_test"> Not unit tested.</span></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature58"><span class="anchor" id="public46"><span class="tag public">public</span></span> <span class="anchor" id="instance43"><span class="tag instance">43</span></span> Array#<span class="feature-name">insert</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">insert</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline">(index, obj...)</code> → Array<div class="p">Inserts the given values before the element with the given index.</div><div class="p">Negative indices count backwards from the end of the array, where <code class="inline">-1</code> is the last element.</div><div class="CodeRay">
588
+ <div class="code"><pre>a = <span class="string"><span class="delimiter">%w{</span><span class="content">a b c d</span><span class="delimiter">}</span></span>
589
+ a.insert(<span class="integer">2</span>, <span class="integer">99</span>) <span class="comment">#=&gt; [&quot;a&quot;, &quot;b&quot;, 99, &quot;c&quot;, &quot;d&quot;]</span>
590
+ a.insert(<span class="integer">-2</span>, <span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>) <span class="comment">#=&gt; [&quot;a&quot;, &quot;b&quot;, 99, &quot;c&quot;, 1, 2, 3, &quot;d&quot;]</span>
591
+ </pre></div>
592
+ </div>
593
+ </div><div class="dev-item"><div class="p indent anchor" id="missing_test11"><span class="hang-indent">​</span><span class="tag missing_test">Missing test</span><span class="dev-text missing_test"> Not unit tested.</span></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature59"><span class="anchor" id="public47"><span class="tag public">public</span></span> <span class="anchor" id="instance44"><span class="tag instance">44</span></span> Array#<span class="feature-name">inspect</span> (alias: <span class="feature-name">to_s</span>)</h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">inspect</code></li></ul></div></div><div class="user-item"><div class="p">Also aliased as: <code class="inline">to_s</code></div><span class="head">Usage</span> <code class="inline"></code> → String<div class="p">Creates a string representation of <code class="inline">self</code>.</div><div class="CodeRay">
594
+ <div class="code"><pre>[<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>].to_s <span class="comment">#=&gt; &quot;[\&quot;a\&quot;, \&quot;b\&quot;, \&quot;c\&quot;]&quot;</span>
595
+ </pre></div>
596
+ </div>
597
+ </div><div class="dev-item"><div class="p indent anchor" id="missing_test12"><span class="hang-indent">​</span><span class="tag missing_test">Missing test</span><span class="dev-text missing_test"> Not unit tested.</span></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature60"><span class="anchor" id="public48"><span class="tag public">public</span></span> <span class="anchor" id="instance45"><span class="tag instance">45</span></span> Array#<span class="feature-name">join</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">join</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline">(separator=$,)</code> → String<div class="p">Returns a string created by converting each element of the array to a string, separated by the given <code class="inline">separator</code>. If the <code class="inline">separator</code> is <code class="inline">nil</code>, it uses current <code class="inline">$,</code>. If both the <code class="inline">separator</code> and <code class="inline">$,</code> are <code class="inline">nil</code>, it uses empty string.</div><div class="CodeRay">
598
+ <div class="code"><pre>[<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>].join <span class="comment">#=&gt; &quot;abc&quot;</span>
599
+ [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>].join(<span class="string"><span class="delimiter">&quot;</span><span class="content">-</span><span class="delimiter">&quot;</span></span>) <span class="comment">#=&gt; &quot;a-b-c&quot;</span>
600
+ </pre></div>
601
+ </div>
602
+ </div><div class="dev-item"><div class="p"><span class="head">Test 60.</span> ruby/test/ruby/test_array.rb:test_join</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
603
+ <div class="code"><pre><span class="global-variable">$,</span> = <span class="string"><span class="delimiter">&quot;</span><span class="delimiter">&quot;</span></span>
604
+ a = <span class="constant">Array</span>[]
605
+ </pre></div>
606
+ </div>
607
+ <div class="anchor" id="success329"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">329</span> <code class="inline">a.<span class="bold">join</span> <span class="verification">==</span><span class="verification"> &quot;&quot;</span></code></div></div><div class="anchor" id="success330"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">330</span> <code class="inline">a.<span class="bold">join</span>(&quot;,&quot;) <span class="verification">==</span><span class="verification"> &quot;&quot;</span></code></div></div><div class="anchor" id="success331"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">331</span> <code class="inline">a.<span class="bold">join</span><span class="verification">.</span><span class="verification">encoding</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> #&lt;Encoding:US-ASCII&gt;</span></code></div></div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
608
+ <div class="code"><pre><span class="global-variable">$,</span> = <span class="string"><span class="delimiter">&quot;</span><span class="delimiter">&quot;</span></span>
609
+ a = <span class="constant">Array</span>[<span class="integer">1</span>, <span class="integer">2</span>]
610
+ </pre></div>
611
+ </div>
612
+ <div class="anchor" id="success332"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">332</span> <code class="inline">a.<span class="bold">join</span> <span class="verification">==</span><span class="verification"> &quot;12&quot;</span></code></div></div><div class="anchor" id="success333"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">333</span> <code class="inline">a.<span class="bold">join</span>(nil) <span class="verification">==</span><span class="verification"> &quot;12&quot;</span></code></div></div><div class="anchor" id="success334"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">334</span> <code class="inline">a.<span class="bold">join</span>(&quot;,&quot;) <span class="verification">==</span><span class="verification"> &quot;1,2&quot;</span></code></div></div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
613
+ <div class="code"><pre><span class="global-variable">$,</span> = <span class="string"><span class="delimiter">&quot;</span><span class="delimiter">&quot;</span></span>
614
+ a = <span class="constant">Array</span>[<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>]
615
+ </pre></div>
616
+ </div>
617
+ <div class="anchor" id="success335"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">335</span> <code class="inline">a.<span class="bold">join</span> <span class="verification">==</span><span class="verification"> &quot;123&quot;</span></code></div></div><div class="anchor" id="success336"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">336</span> <code class="inline">a.<span class="bold">join</span>(nil) <span class="verification">==</span><span class="verification"> &quot;123&quot;</span></code></div></div><div class="anchor" id="success337"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">337</span> <code class="inline">a.<span class="bold">join</span>(&quot;,&quot;) <span class="verification">==</span><span class="verification"> &quot;1,2,3&quot;</span></code></div></div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
618
+ <div class="code"><pre><span class="global-variable">$,</span> = <span class="string"><span class="delimiter">&quot;</span><span class="content">:</span><span class="delimiter">&quot;</span></span>
619
+ a = <span class="constant">Array</span>[<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>]
620
+ </pre></div>
621
+ </div>
622
+ <div class="anchor" id="success338"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">338</span> <code class="inline">a.<span class="bold">join</span> <span class="verification">==</span><span class="verification"> &quot;1:2:3&quot;</span></code></div></div><div class="anchor" id="success339"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">339</span> <code class="inline">a.<span class="bold">join</span>(nil) <span class="verification">==</span><span class="verification"> &quot;1:2:3&quot;</span></code></div></div><div class="anchor" id="success340"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">340</span> <code class="inline">a.<span class="bold">join</span>(&quot;,&quot;) <span class="verification">==</span><span class="verification"> &quot;1,2,3&quot;</span></code></div></div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
623
+ <div class="code"><pre><span class="global-variable">$,</span> = <span class="string"><span class="delimiter">&quot;</span><span class="delimiter">&quot;</span></span>
624
+ a = <span class="constant">Array</span>[<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>]
625
+ a.taint
626
+ </pre></div>
627
+ </div>
628
+ <div class="anchor" id="success341"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">341</span> <code class="inline">a.<span class="bold">join</span><span class="verification">.</span><span class="verification">tainted?</span><span class="verification"></span></code></div></div><div class="p"><span class="head">Test 60.1.</span> bug5902 ruby-core:42161</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
629
+ <div class="code"><pre>sep = <span class="string"><span class="delimiter">&quot;</span><span class="content">:</span><span class="delimiter">&quot;</span></span>.taint</pre></div>
630
+ </div>
631
+ <div class="anchor" id="success342"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">342</span> <code class="inline">[].<span class="bold">join</span>(sep)<span class="verification">.</span><span class="verification">tainted?</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> false</span></code></div></div><div class="anchor" id="success343"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">343</span> <code class="inline">[1].<span class="bold">join</span>(sep)<span class="verification">.</span><span class="verification">tainted?</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> false</span></code></div></div><div class="anchor" id="success344"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">344</span> <code class="inline">[1, 2].<span class="bold">join</span>(sep)<span class="verification">.</span><span class="verification">tainted?</span><span class="verification"></span></code></div></div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
632
+ <div class="code"><pre>e = <span class="string"><span class="delimiter">&quot;</span><span class="delimiter">&quot;</span></span>.force_encoding(<span class="string"><span class="delimiter">&quot;</span><span class="content">EUC-JP</span><span class="delimiter">&quot;</span></span>)
633
+ u = <span class="string"><span class="delimiter">&quot;</span><span class="delimiter">&quot;</span></span>.force_encoding(<span class="string"><span class="delimiter">&quot;</span><span class="content">UTF-8</span><span class="delimiter">&quot;</span></span>)
634
+ </pre></div>
635
+ </div>
636
+ <div class="anchor" id="success345"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">345</span> <code class="inline">[[]].<span class="bold">join</span><span class="verification">.</span><span class="verification">encoding</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> #&lt;Encoding:US-ASCII&gt;</span></code></div></div><div class="anchor" id="success346"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">346</span> <code class="inline">[1, [u]].<span class="bold">join</span><span class="verification">.</span><span class="verification">encoding</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> #&lt;Encoding:US-ASCII&gt;</span></code></div></div><div class="anchor" id="success347"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">347</span> <code class="inline">[u, [e]].<span class="bold">join</span><span class="verification">.</span><span class="verification">encoding</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> #&lt;Encoding:UTF-8&gt;</span></code></div></div><div class="anchor" id="success348"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">348</span> <code class="inline">[u, [1]].<span class="bold">join</span><span class="verification">.</span><span class="verification">encoding</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> #&lt;Encoding:UTF-8&gt;</span></code></div></div><div class="p"><span class="head">Test 60.2.</span> bug5379 ruby-core:39776</div><div class="anchor" id="success349"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">349</span> <code class="inline">[[], u, nil].<span class="bold">join</span><span class="verification">.</span><span class="verification">encoding</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> #&lt;Encoding:US-ASCII&gt;</span></code></div></div><div class="anchor" id="success350"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">350</span> <code class="inline">[[], &quot;あ&quot;, nil].<span class="bold">join</span><span class="verification">.</span><span class="verification">encoding</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> #&lt;Encoding:UTF-8&gt;</span></code></div></div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
637
+ <div class="code"><pre><span class="global-variable">$,</span> = <span class="predefined-constant">nil</span></pre></div>
638
+ </div>
639
+ </div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature61"><span class="anchor" id="public49"><span class="tag public">public</span></span> <span class="anchor" id="instance46"><span class="tag instance">46</span></span> Array#<span class="feature-name">keep_if</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">keep_if</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">#select!</code></div><span class="head">Usage</span> <code class="inline">{|item| block}</code> → Array<div class="p">Deletes every element of self for which the given block evaluates to <code class="inline">false</code>.</div><span class="head">Usage</span> <code class="inline"></code> → Enumerator<div class="CodeRay">
640
+ <div class="code"><pre>a = <span class="string"><span class="delimiter">%w{</span><span class="content">a b c d e f</span><span class="delimiter">}</span></span>
641
+ a.keep_if{|v| v =~ <span class="regexp"><span class="delimiter">/</span><span class="content">[aeiou]</span><span class="delimiter">/</span></span>} <span class="comment">#=&gt; [&quot;a&quot;, &quot;e&quot;]</span>
642
+ </pre></div>
643
+ </div>
644
+ </div><div class="dev-item"><div class="p indent anchor" id="missing_test13"><span class="hang-indent">​</span><span class="tag missing_test">Missing test</span><span class="dev-text missing_test"> Not unit tested.</span></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature62"><span class="anchor" id="public50"><span class="tag public">public</span></span> <span class="anchor" id="instance47"><span class="tag instance">47</span></span> Array#<span class="feature-name">last</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">last</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">#first</code> for the opposite effect.</div><span class="head">Usage</span> <code class="inline"></code> → Object | <code class="inline">nil</code><div class="p">Returns the last element of <code class="inline">self</code>. If the array is empty, returns <code class="inline">nil</code>.</div><span class="head">Usage</span> <code class="inline">(n)</code> → Array<div class="p">Returns the last element(s) of <code class="inline">self</code>.</div><div class="CodeRay">
645
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">w</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">x</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">y</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">z</span><span class="delimiter">&quot;</span></span>]
646
+ a.last <span class="comment">#=&gt; &quot;z&quot;</span>
647
+ a.last(<span class="integer">2</span>) <span class="comment">#=&gt; [&quot;y&quot;, &quot;z&quot;]</span>
648
+ </pre></div>
649
+ </div>
650
+ </div><div class="dev-item"><div class="p"><span class="head">Test 61.</span> ruby/test/ruby/test_array.rb:test_last</div><div class="anchor" id="success351"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">351</span> <code class="inline">[].<span class="bold">last</span><span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="anchor" id="success352"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">352</span> <code class="inline">[1].<span class="bold">last</span> <span class="verification">==</span><span class="verification"> 1</span></code></div></div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
651
+ <div class="code"><pre>a = <span class="constant">Array</span>[*(<span class="integer">3</span>..<span class="integer">99</span>).to_a]</pre></div>
652
+ </div>
653
+ <div class="anchor" id="success353"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">353</span> <code class="inline">a.<span class="bold">last</span> <span class="verification">==</span><span class="verification"> 99</span></code></div></div><div class="p"><span class="head">Test 62.</span> ruby/test/ruby/test_array.rb:test_beg_end_0:2/6</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
654
+ <div class="code"><pre>x = [<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>, <span class="integer">4</span>, <span class="integer">5</span>]</pre></div>
655
+ </div>
656
+ <div class="anchor" id="success354"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">354</span> <code class="inline">x.<span class="bold">last</span> <span class="verification">==</span><span class="verification"> 5</span></code></div></div><div class="anchor" id="success355"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">355</span> <code class="inline">x.<span class="bold">last</span>(1) <span class="verification">==</span><span class="verification"> [5]</span></code></div></div><div class="anchor" id="success356"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">356</span> <code class="inline">x.<span class="bold">last</span>(3) <span class="verification">==</span><span class="verification"> [3, 4, 5]</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature63"><span class="anchor" id="public51"><span class="tag public">public</span></span> <span class="anchor" id="instance48"><span class="tag instance">48</span></span> Array#<span class="feature-name">length</span> (alias: <span class="feature-name">size</span>)</h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">length</code></li></ul></div></div><div class="user-item"><div class="p">Also aliased as: <code class="inline">size</code></div><span class="head">Usage</span> <code class="inline"></code> → Integer<div class="p">Returns the number of elements in <code class="inline">self</code>. May be zero.</div><div class="CodeRay">
657
+ <div class="code"><pre>[<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>, <span class="integer">4</span>, <span class="integer">5</span>].length <span class="comment">#=&gt; 5</span>
658
+ [].length <span class="comment">#=&gt; 0</span>
659
+ </pre></div>
660
+ </div>
661
+ </div><div class="dev-item"><div class="p"><span class="head">Test 63.</span> ruby/test/ruby/test_array.rb:test_length</div><div class="anchor" id="success357"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">357</span> <code class="inline">[].<span class="bold">length</span><span class="verification">.</span><span class="verification">zero?</span><span class="verification"></span></code></div></div><div class="anchor" id="success358"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">358</span> <code class="inline">[1].<span class="bold">length</span> <span class="verification">==</span><span class="verification"> 1</span></code></div></div><div class="anchor" id="success359"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">359</span> <code class="inline">[1, nil].<span class="bold">length</span> <span class="verification">==</span><span class="verification"> 2</span></code></div></div><div class="anchor" id="success360"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">360</span> <code class="inline">[nil, 1].<span class="bold">length</span> <span class="verification">==</span><span class="verification"> 2</span></code></div></div><div class="anchor" id="success361"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">361</span> <code class="inline">Array[*(0..233).to_a].<span class="bold">length</span> <span class="verification">==</span><span class="verification"> 234</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature64"><span class="anchor" id="public52"><span class="tag public">public</span></span> <span class="anchor" id="instance49"><span class="tag instance">49</span></span> Array#<span class="feature-name">map</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">map</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">Enumerable#collect</code>.</div><span class="head">Usage</span> <code class="inline">{|item| block}</code> → Array<div class="p">Invokes the given block once for each element of <code class="inline">self</code>.</div><div class="p">Creates a new array containing the values returned by the block.</div><span class="head">Usage</span> <code class="inline"></code> → Enumerator<div class="CodeRay">
662
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">d</span><span class="delimiter">&quot;</span></span>]
663
+ a.collect{|x| x + <span class="string"><span class="delimiter">&quot;</span><span class="content">!</span><span class="delimiter">&quot;</span></span>} <span class="comment">#=&gt; [&quot;a!&quot;, &quot;b!&quot;, &quot;c!&quot;, &quot;d!&quot;]</span>
664
+ a.map.with_index{|x, i| x * i} <span class="comment">#=&gt; [&quot;&quot;, &quot;b&quot;, &quot;cc&quot;, &quot;ddd&quot;]</span>
665
+ a <span class="comment">#=&gt; [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;]</span>
666
+ </pre></div>
667
+ </div>
668
+ </div><div class="dev-item"><div class="p"><span class="head">Test 64.</span> ruby/test/ruby/test_array.rb:test_collect</div><div class="anchor" id="success362"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">362</span> <code class="inline">[1, &quot;cat&quot;, 1..1].<span class="bold">map</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:1365)} <span class="verification">==</span><span class="verification"> [Fixnum, String, Range]</span></code></div></div><div class="anchor" id="success363"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">363</span> <code class="inline">[1, &quot;cat&quot;, 1..1].<span class="bold">map</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:1366)} <span class="verification">==</span><span class="verification"> [99, 99, 99]</span></code></div></div><div class="anchor" id="success364"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">364</span> <code class="inline">[].<span class="bold">map</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:1367)} <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="anchor" id="success365"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">365</span> <code class="inline">[1, 2, 3].<span class="bold">map</span><span class="verification">.</span><span class="verification">kind_of?</span><span class="verification">(Enumerator)</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature65"><span class="anchor" id="public53"><span class="tag public">public</span></span> <span class="anchor" id="instance50"><span class="tag instance">50</span></span> Array#<span class="feature-name">map!</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">map!</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">Enumerable#collect</code>.</div><span class="head">Usage</span> <code class="inline">{|item| block}</code> → Array<div class="p">Invokes the given block once for each element of <code class="inline">self</code>, replacing the element with the value returned by the block.</div><span class="head">Usage</span> <code class="inline"></code> → Enumerator<div class="CodeRay">
669
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">d</span><span class="delimiter">&quot;</span></span>]
670
+ a.map!{|x| x + <span class="string"><span class="delimiter">&quot;</span><span class="content">!</span><span class="delimiter">&quot;</span></span>}
671
+ a <span class="comment">#=&gt; [&quot;a!&quot;, &quot;b!&quot;, &quot;c!&quot;, &quot;d!&quot;]</span>
672
+ a.collect!.with_index{|x, i| x[<span class="integer">0</span>...i]}
673
+ a <span class="comment">#=&gt; [&quot;&quot;, &quot;b&quot;, &quot;c!&quot;, &quot;d!&quot;]</span>
674
+ </pre></div>
675
+ </div>
676
+ </div><div class="dev-item"><div class="p"><span class="head">Test 65.</span> ruby/test/ruby/test_array.rb:test_collect!</div><div class="anchor" id="success366"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">366</span> <code class="inline">[1, &quot;cat&quot;, 1..1].<span class="bold">map!</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:1383)} <span class="verification">==</span><span class="verification"> [Fixnum, String, Range]</span></code></div></div><div class="anchor" id="success367"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">367</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [Fixnum, String, Range]</span></code></div></div><div class="anchor" id="success368"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">368</span> <code class="inline">[1, &quot;cat&quot;, 1..1].<span class="bold">map!</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:1385)} <span class="verification">==</span><span class="verification"> [99, 99, 99]</span></code></div></div><div class="anchor" id="success369"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">369</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [99, 99, 99]</span></code></div></div><div class="anchor" id="success370"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">370</span> <code class="inline">[].<span class="bold">map!</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:1387)} <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="anchor" id="success371"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">371</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="p"><span class="head">Test 66.</span> ruby/test/ruby/test_array.rb:test_map!</div><div class="anchor" id="success372"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">372</span> <code class="inline">[1, &quot;cat&quot;, 1..1].<span class="bold">map!</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:1390)} <span class="verification">==</span><span class="verification"> [Fixnum, String, Range]</span></code></div></div><div class="anchor" id="success373"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">373</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [Fixnum, String, Range]</span></code></div></div><div class="anchor" id="success374"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">374</span> <code class="inline">[1, &quot;cat&quot;, 1..1].<span class="bold">map!</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:1392)} <span class="verification">==</span><span class="verification"> [99, 99, 99]</span></code></div></div><div class="anchor" id="success375"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">375</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [99, 99, 99]</span></code></div></div><div class="anchor" id="success376"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">376</span> <code class="inline">[].<span class="bold">map!</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:1394)} <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="anchor" id="success377"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">377</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> []</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature66"><span class="anchor" id="public54"><span class="tag public">public</span></span> <span class="anchor" id="instance51"><span class="tag instance">51</span></span> Array#<span class="feature-name">pack</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">pack</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">String#unpack</code>.</div><span class="head">Usage</span> <code class="inline">(aTemplateString)</code> → String<div class="p">Packs the contents of <code class="inline">self</code> into a binary sequence according to the directives in <code class="inline">aTemplateString</code> (see the table below) Directives <code class="inline">A</code>, <code class="inline">a</code>, and <code class="inline">Z</code> may be followed by a count, which gives the width of the resulting field. The remaining directives also may take a count, indicating the number of array elements to convert. If the count is an asterisk (<code class="inline">*</code>), all remaining array elements will be converted. Any of the directives <code class="inline">sSiIlL</code> may be followed by an underscore (<code class="inline">_</code>) or exclamation mark (<code class="inline">!</code>) to use the underlying platform’s native size for the specified type; otherwise, they use a platform-independent size. Spaces are ignored in the template string.</div><div class="CodeRay">
677
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>]
678
+ n = [<span class="integer">65</span>, <span class="integer">66</span>, <span class="integer">67</span>]
679
+ a.pack(<span class="string"><span class="delimiter">&quot;</span><span class="content">A3A3A3</span><span class="delimiter">&quot;</span></span>) <span class="comment">#=&gt; &quot;a b c &quot;</span>
680
+ a.pack(<span class="string"><span class="delimiter">&quot;</span><span class="content">a3a3a3</span><span class="delimiter">&quot;</span></span>) <span class="comment">#=&gt; &quot;a\000\000b\000\000c\000\000&quot;</span>
681
+ n.pack(<span class="string"><span class="delimiter">&quot;</span><span class="content">ccc</span><span class="delimiter">&quot;</span></span>) <span class="comment">#=&gt; &quot;ABC&quot;</span>
682
+ </pre></div>
683
+ </div>
684
+ <div class="p">Directives for pack.</div><div class="CodeRay">
685
+ <div class="code"><pre><span class="constant">Integer</span> | <span class="constant">Array</span> |
686
+ <span class="constant">Directive</span> | <span class="constant">Element</span> | <span class="constant">Meaning</span>
687
+ ---------------------------------------------------------------------------
688
+ <span class="constant">C</span> | <span class="constant">Integer</span> | <span class="integer">8</span>-bit unsigned (unsigned char)
689
+ <span class="constant">S</span> | <span class="constant">Integer</span> | <span class="integer">16</span>-bit unsigned, native endian (uint16_t)
690
+ <span class="constant">L</span> | <span class="constant">Integer</span> | <span class="integer">32</span>-bit unsigned, native endian (uint32_t)
691
+ <span class="constant">Q</span> | <span class="constant">Integer</span> | <span class="integer">64</span>-bit unsigned, native endian (uint64_t)
692
+ | |
693
+ c | <span class="constant">Integer</span> | <span class="integer">8</span>-bit signed (signed char)
694
+ s | <span class="constant">Integer</span> | <span class="integer">16</span>-bit signed, native endian (int16_t)
695
+ l | <span class="constant">Integer</span> | <span class="integer">32</span>-bit signed, native endian (int32_t)
696
+ q | <span class="constant">Integer</span> | <span class="integer">64</span>-bit signed, native endian (int64_t)
697
+ | |
698
+ <span class="constant">S_</span>, S! | <span class="constant">Integer</span> | unsigned short, native endian
699
+ <span class="constant">I</span>, <span class="constant">I_</span>, I! | <span class="constant">Integer</span> | unsigned int, native endian
700
+ <span class="constant">L_</span>, L! | <span class="constant">Integer</span> | unsigned long, native endian
701
+ <span class="constant">Q_</span>, Q! | <span class="constant">Integer</span> | unsigned long long, native endian (<span class="constant">ArgumentError</span>
702
+ | | <span class="keyword">if</span> the platform has no long long type.)
703
+ | | (<span class="constant">Q_</span> <span class="keyword">and</span> Q! is available since <span class="constant">Ruby</span> <span class="float">2.1</span>.)
704
+ | |
705
+ s_, s! | <span class="constant">Integer</span> | signed short, native endian
706
+ i, i_, i! | <span class="constant">Integer</span> | signed int, native endian
707
+ l_, l! | <span class="constant">Integer</span> | signed long, native endian
708
+ q_, q! | <span class="constant">Integer</span> | signed long long, native endian (<span class="constant">ArgumentError</span>
709
+ | | <span class="keyword">if</span> the platform has no long long type.)
710
+ | | (q_ <span class="keyword">and</span> q! is available since <span class="constant">Ruby</span> <span class="float">2.1</span>.)
711
+ | |
712
+ <span class="constant">S</span>&gt; <span class="constant">L</span>&gt; <span class="constant">Q</span>&gt; | <span class="constant">Integer</span> | same as the directives without <span class="string"><span class="delimiter">&quot;</span><span class="content">&gt;</span><span class="delimiter">&quot;</span></span> except
713
+ s&gt; l&gt; q&gt; | | big endian
714
+ S!&gt; I!&gt; | | (available since <span class="constant">Ruby</span> <span class="float">1.9</span>.<span class="error">3</span>)
715
+ L!&gt; Q!&gt; | | <span class="string"><span class="delimiter">&quot;</span><span class="content">S&gt;</span><span class="delimiter">&quot;</span></span> is same as <span class="string"><span class="delimiter">&quot;</span><span class="content">n</span><span class="delimiter">&quot;</span></span>
716
+ s!&gt; i!&gt; | | <span class="string"><span class="delimiter">&quot;</span><span class="content">L&gt;</span><span class="delimiter">&quot;</span></span> is same as <span class="string"><span class="delimiter">&quot;</span><span class="content">N</span><span class="delimiter">&quot;</span></span>
717
+ l!&gt; q!&gt; | |
718
+ | |
719
+ <span class="constant">S</span>&lt; <span class="constant">L</span>&lt; <span class="constant">Q</span>&lt; | <span class="constant">Integer</span> | same as the directives without <span class="string"><span class="delimiter">&quot;</span><span class="content">&lt;</span><span class="delimiter">&quot;</span></span> except
720
+ s&lt; l&lt; q&lt; | | little endian
721
+ S!&lt; I!&lt; | | (available since <span class="constant">Ruby</span> <span class="float">1.9</span>.<span class="error">3</span>)
722
+ L!&lt; Q!&lt; | | <span class="string"><span class="delimiter">&quot;</span><span class="content">S&lt;</span><span class="delimiter">&quot;</span></span> is same as <span class="string"><span class="delimiter">&quot;</span><span class="content">v</span><span class="delimiter">&quot;</span></span>
723
+ s!&lt; i!&lt; | | <span class="string"><span class="delimiter">&quot;</span><span class="content">L&lt;</span><span class="delimiter">&quot;</span></span> is same as <span class="string"><span class="delimiter">&quot;</span><span class="content">V</span><span class="delimiter">&quot;</span></span>
724
+ l!&lt; q!&lt; | |
725
+ | |
726
+ n | <span class="constant">Integer</span> | <span class="integer">16</span>-bit unsigned, network (big-endian) byte order
727
+ <span class="constant">N</span> | <span class="constant">Integer</span> | <span class="integer">32</span>-bit unsigned, network (big-endian) byte order
728
+ v | <span class="constant">Integer</span> | <span class="integer">16</span>-bit unsigned, <span class="constant">VAX</span> (little-endian) byte order
729
+ <span class="constant">V</span> | <span class="constant">Integer</span> | <span class="integer">32</span>-bit unsigned, <span class="constant">VAX</span> (little-endian) byte order
730
+ | |
731
+ <span class="constant">U</span> | <span class="constant">Integer</span> | <span class="constant">UTF</span>-<span class="integer">8</span> character
732
+ w | <span class="constant">Integer</span> | <span class="constant">BER</span>-compressed integer
733
+
734
+ <span class="constant">Float</span> | |
735
+ <span class="constant">Directive</span> | | <span class="constant">Meaning</span>
736
+ ---------------------------------------------------------------------------
737
+ <span class="constant">D</span>, d | <span class="constant">Float</span> | double-precision, native format
738
+ <span class="constant">F</span>, f | <span class="constant">Float</span> | single-precision, native format
739
+ <span class="constant">E</span> | <span class="constant">Float</span> | double-precision, little-endian byte order
740
+ e | <span class="constant">Float</span> | single-precision, little-endian byte order
741
+ <span class="constant">G</span> | <span class="constant">Float</span> | double-precision, network (big-endian) byte order
742
+ g | <span class="constant">Float</span> | single-precision, network (big-endian) byte order
743
+
744
+ <span class="constant">String</span> | |
745
+ <span class="constant">Directive</span> | | <span class="constant">Meaning</span>
746
+ ---------------------------------------------------------------------------
747
+ <span class="constant">A</span> | <span class="constant">String</span> | arbitrary binary string (space padded, count is width)
748
+ a | <span class="constant">String</span> | arbitrary binary string (null padded, count is width)
749
+ <span class="constant">Z</span> | <span class="constant">String</span> | same as <span class="shell"><span class="delimiter">`</span><span class="delimiter">`</span></span>a<span class="string"><span class="delimiter">'</span><span class="delimiter">'</span></span>, except that null is added with *
750
+ <span class="constant">B</span> | <span class="constant">String</span> | bit string (<span class="constant">MSB</span> first)
751
+ b | <span class="constant">String</span> | bit string (<span class="constant">LSB</span> first)
752
+ <span class="constant">H</span> | <span class="constant">String</span> | hex string (high nibble first)
753
+ h | <span class="constant">String</span> | hex string (low nibble first)
754
+ u | <span class="constant">String</span> | <span class="constant">UU</span>-encoded string
755
+ <span class="constant">M</span> | <span class="constant">String</span> | quoted printable, <span class="constant">MIME</span> encoding (see <span class="constant">RFC2045</span>)
756
+ m | <span class="constant">String</span> | base64 encoded string (see <span class="constant">RFC</span> <span class="integer">2045</span>, count is width)
757
+ | | (<span class="keyword">if</span> count is <span class="integer">0</span>, no line feed are added, see <span class="constant">RFC</span> <span class="integer">4648</span>)
758
+ <span class="constant">P</span> | <span class="constant">String</span> | pointer to a structure (fixed-length string)
759
+ p | <span class="constant">String</span> | pointer to a null-terminated string
760
+
761
+ <span class="constant">Misc</span>. | |
762
+ <span class="constant">Directive</span> | | <span class="constant">Meaning</span>
763
+ ---------------------------------------------------------------------------
764
+ <span class="error">@</span> | --- | moves to absolute position
765
+ <span class="constant">X</span> | --- | back up a byte
766
+ x | --- | null byte
767
+ </pre></div>
768
+ </div>
769
+ <table><tr><td style="text-align:center;">Integer Directive</td><td style="text-align:center;">Array Element</td><td style="text-align:center;">Meaning</td></tr><tr><td style="text-align:left;">C</td><td style="text-align:left;">Integer</td><td>8-bit unsigned (unsigned char)</td></tr><tr><td style="text-align:left;">S</td><td style="text-align:left;">Integer</td><td>16-bit unsigned, native endian (uint16_t)</td></tr><tr><td style="text-align:left;">L</td><td style="text-align:left;">Integer</td><td>32-bit unsigned, native endian (uint32_t)</td></tr><tr><td style="text-align:left;">Q</td><td style="text-align:left;">Integer</td><td>64-bit unsigned, native endian (uint64_t)</td></tr><tr><td style="text-align:left;">c</td><td style="text-align:left;">Integer</td><td>8-bit signed (signed char)</td></tr><tr><td style="text-align:left;">s</td><td style="text-align:left;">Integer</td><td>16-bit signed, native endian (int16_t)</td></tr><tr><td style="text-align:left;">l</td><td style="text-align:left;">Integer</td><td>32-bit signed, native endian (int32_t)</td></tr><tr><td style="text-align:left;">q</td><td style="text-align:left;">Integer</td><td>64-bit signed, native endian (int64_t)</td></tr><tr><td style="text-align:left;">S_, S!</td><td style="text-align:left;">Integer</td><td>unsigned short, native endian</td></tr><tr><td style="text-align:left;">I, I_, I!</td><td style="text-align:left;">Integer</td><td>unsigned int, native endian</td></tr><tr><td style="text-align:left;">L_, L!</td><td style="text-align:left;">Integer</td><td>unsigned long, native endian</td></tr><tr><td style="text-align:left;">Q_, Q!</td><td style="text-align:left;">Integer</td><td>unsigned long long, native endian (ArgumentError
770
+ if the platform has no long long type. Q_ and Q! are available since Ruby 2.1.)</td></tr><tr><td style="text-align:left;">s_, s!</td><td style="text-align:left;">Integer</td><td>signed short, native endian</td></tr><tr><td style="text-align:left;">i, i_, i!</td><td style="text-align:left;">Integer</td><td>signed int, native endian</td></tr><tr><td style="text-align:left;">l_, l!</td><td style="text-align:left;">Integer</td><td>signed long, native endian</td></tr><tr><td style="text-align:left;">q_, q!</td><td style="text-align:left;">Integer</td><td>signed long long, native endian (ArgumentError
771
+ if the platform has no long long type. q_ and q! are available since Ruby 2.1.)</td></tr><tr><td style="text-align:left;">S&gt; L&gt; Q&gt;</td><td style="text-align:left;">Integer</td><td>same as the directives without &quot;&gt;&quot; except</td></tr><tr><td style="text-align:left;">s&gt; l&gt; q&gt;</td><td></td><td>big endian</td></tr></table></div><div class="dev-item"><div class="p"><span class="head">Test 67.</span> ruby/test/ruby/test_array.rb:test_pack</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
772
+ <div class="code"><pre>a = <span class="constant">Array</span>[*<span class="string"><span class="delimiter">%w(</span><span class="content">cat wombat x yy</span><span class="delimiter">)</span></span>]</pre></div>
773
+ </div>
774
+ <div class="anchor" id="success378"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">378</span> <code class="inline">a.<span class="bold">pack</span>(&quot;A3A3A3A3&quot;) <span class="verification">==</span><span class="verification"> &quot;catwomx yy &quot;</span></code></div></div><div class="anchor" id="success379"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">379</span> <code class="inline">a.<span class="bold">pack</span>(&quot;A*&quot;) <span class="verification">==</span><span class="verification"> &quot;cat&quot;</span></code></div></div><div class="anchor" id="success380"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">380</span> <code class="inline">a.<span class="bold">pack</span>(&quot;A3@1A3@2A3A3&quot;) <span class="verification">==</span><span class="verification"> &quot;cwx yy &quot;</span></code></div></div><div class="anchor" id="success381"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">381</span> <code class="inline">a.<span class="bold">pack</span>(&quot;a3a3a3a3&quot;) <span class="verification">==</span><span class="verification"> &quot;catwomx\u0000\u0000yy\u0000&quot;</span></code></div></div><div class="anchor" id="success382"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">382</span> <code class="inline">a.<span class="bold">pack</span>(&quot;a*&quot;) <span class="verification">==</span><span class="verification"> &quot;cat&quot;</span></code></div></div><div class="anchor" id="success383"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">383</span> <code class="inline">a.<span class="bold">pack</span>(&quot;a2&quot;) <span class="verification">==</span><span class="verification"> &quot;ca&quot;</span></code></div></div><div class="anchor" id="success384"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">384</span> <code class="inline">a.<span class="bold">pack</span>(&quot;a5&quot;) <span class="verification">==</span><span class="verification"> &quot;cat\u0000\u0000&quot;</span></code></div></div><div class="anchor" id="success385"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">385</span> <code class="inline">[&quot;01100001&quot;].<span class="bold">pack</span>(&quot;B8&quot;) <span class="verification">==</span><span class="verification"> &quot;a&quot;</span></code></div></div><div class="anchor" id="success386"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">386</span> <code class="inline">[&quot;01100001&quot;].<span class="bold">pack</span>(&quot;B*&quot;) <span class="verification">==</span><span class="verification"> &quot;a&quot;</span></code></div></div><div class="anchor" id="success387"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">387</span> <code class="inline">[&quot;0110000100110111&quot;].<span class="bold">pack</span>(&quot;B8&quot;) <span class="verification">==</span><span class="verification"> &quot;a&quot;</span></code></div></div><div class="anchor" id="success388"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">388</span> <code class="inline">[&quot;0110000100110111&quot;].<span class="bold">pack</span>(&quot;B16&quot;) <span class="verification">==</span><span class="verification"> &quot;a7&quot;</span></code></div></div><div class="anchor" id="success389"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">389</span> <code class="inline">[&quot;01100001&quot;, &quot;00110111&quot;].<span class="bold">pack</span>(&quot;B8B8&quot;) <span class="verification">==</span><span class="verification"> &quot;a7&quot;</span></code></div></div><div class="anchor" id="success390"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">390</span> <code class="inline">[&quot;01100001&quot;].<span class="bold">pack</span>(&quot;B4&quot;) <span class="verification">==</span><span class="verification"> &quot;`&quot;</span></code></div></div><div class="anchor" id="success391"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">391</span> <code class="inline">[&quot;01100001&quot;].<span class="bold">pack</span>(&quot;B2&quot;) <span class="verification">==</span><span class="verification"> &quot;@&quot;</span></code></div></div><div class="anchor" id="bug5"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">5</span> <code class="inline">[&quot;01100001&quot;].<span class="bold">pack</span>(&quot;b8&quot;) <span class="verification">==</span><span class="verification"> &quot;\x86&quot;</span></code></div><ul><li><code class="inline">pack</code>: <span class="dev-text bug">The receiver of verification <code class="inline">==</code> is <code class="inline">&quot;\x86&quot;</code>.</span></li></ul></div><div class="anchor" id="bug6"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">6</span> <code class="inline">[&quot;01100001&quot;].<span class="bold">pack</span>(&quot;b*&quot;) <span class="verification">==</span><span class="verification"> &quot;\x86&quot;</span></code></div><ul><li><code class="inline">pack</code>: <span class="dev-text bug">The receiver of verification <code class="inline">==</code> is <code class="inline">&quot;\x86&quot;</code>.</span></li></ul></div><div class="anchor" id="bug7"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">7</span> <code class="inline">[&quot;0110000100110111&quot;].<span class="bold">pack</span>(&quot;b8&quot;) <span class="verification">==</span><span class="verification"> &quot;\x86&quot;</span></code></div><ul><li><code class="inline">pack</code>: <span class="dev-text bug">The receiver of verification <code class="inline">==</code> is <code class="inline">&quot;\x86&quot;</code>.</span></li></ul></div><div class="anchor" id="bug8"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">8</span> <code class="inline">[&quot;0110000100110111&quot;].<span class="bold">pack</span>(&quot;b16&quot;) <span class="verification">==</span><span class="verification"> &quot;\x86\xEC&quot;</span></code></div><ul><li><code class="inline">pack</code>: <span class="dev-text bug">The receiver of verification <code class="inline">==</code> is <code class="inline">&quot;\x86\xEC&quot;</code>.</span></li></ul></div><div class="anchor" id="bug9"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">9</span> <code class="inline">[&quot;01100001&quot;, &quot;00110111&quot;].<span class="bold">pack</span>(&quot;b8b8&quot;) <span class="verification">==</span><span class="verification"> &quot;\x86\xEC&quot;</span></code></div><ul><li><code class="inline">pack</code>: <span class="dev-text bug">The receiver of verification <code class="inline">==</code> is <code class="inline">&quot;\x86\xEC&quot;</code>.</span></li></ul></div><div class="anchor" id="success392"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">392</span> <code class="inline">[&quot;01100001&quot;].<span class="bold">pack</span>(&quot;b4&quot;) <span class="verification">==</span><span class="verification"> &quot;\u0006&quot;</span></code></div></div><div class="anchor" id="success393"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">393</span> <code class="inline">[&quot;01100001&quot;].<span class="bold">pack</span>(&quot;b2&quot;) <span class="verification">==</span><span class="verification"> &quot;\u0002&quot;</span></code></div></div><div class="anchor" id="success394"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">394</span> <code class="inline">[65, 66, 67].<span class="bold">pack</span>(&quot;C3&quot;) <span class="verification">==</span><span class="verification"> &quot;ABC&quot;</span></code></div></div><div class="anchor" id="bug10"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">10</span> <code class="inline">[-1, 66, 67].<span class="bold">pack</span>(&quot;C*&quot;) <span class="verification">==</span><span class="verification"> &quot;\xFFBC&quot;</span></code></div><ul><li><code class="inline">pack</code>: <span class="dev-text bug">The receiver of verification <code class="inline">==</code> is <code class="inline">&quot;\xFFBC&quot;</code>.</span></li></ul></div><div class="anchor" id="success395"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">395</span> <code class="inline">[65, 66, 67].<span class="bold">pack</span>(&quot;c3&quot;) <span class="verification">==</span><span class="verification"> &quot;ABC&quot;</span></code></div></div><div class="anchor" id="bug11"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">11</span> <code class="inline">[-1, 66, 67].<span class="bold">pack</span>(&quot;c*&quot;) <span class="verification">==</span><span class="verification"> &quot;\xFFBC&quot;</span></code></div><ul><li><code class="inline">pack</code>: <span class="dev-text bug">The receiver of verification <code class="inline">==</code> is <code class="inline">&quot;\xFFBC&quot;</code>.</span></li></ul></div><div class="anchor" id="success396"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">396</span> <code class="inline">[&quot;4142&quot;, &quot;0a&quot;, &quot;12&quot;].<span class="bold">pack</span>(&quot;H4H2H1&quot;) <span class="verification">==</span><span class="verification"> &quot;AB\n\u0010&quot;</span></code></div></div><div class="anchor" id="success397"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">397</span> <code class="inline">[&quot;1424&quot;, &quot;a0&quot;, &quot;21&quot;].<span class="bold">pack</span>(&quot;h4h2h1&quot;) <span class="verification">==</span><span class="verification"> &quot;AB\n\u0002&quot;</span></code></div></div><div class="anchor" id="success398"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">398</span> <code class="inline">[&quot;abc\u0002def&quot;, &quot;cat&quot;, &quot;\u0001&quot;].<span class="bold">pack</span>(&quot;M9M3M4&quot;) <span class="verification">==</span><span class="verification"> &quot;abc=02def=\ncat=\n=01=\n&quot;</span></code></div></div><div class="anchor" id="success399"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">399</span> <code class="inline">[&quot;hello\n&quot;].<span class="bold">pack</span>(&quot;m&quot;) <span class="verification">==</span><span class="verification"> &quot;aGVsbG8K\n&quot;</span></code></div></div><div class="anchor" id="success400"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">400</span> <code class="inline">[&quot;hello\nhello\n&quot;].<span class="bold">pack</span>(&quot;u&quot;) <span class="verification">==</span><span class="verification"> &quot;,:&amp;5L;&amp;\\*:&amp;5L;&amp;\\*\n&quot;</span></code></div></div><div class="anchor" id="success401"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">401</span> <code class="inline">[169, 66, 8800].<span class="bold">pack</span>(&quot;U*&quot;) <span class="verification">==</span><span class="verification"> &quot;©B≠&quot;</span></code></div></div><div class="p"><span class="head">Test 67.1.</span> Need the expression in here to force <code class="inline">ary[5]</code> to be numeric. This avoids <code class="inline">test2</code> failing because <code class="inline">ary2</code> goes str-&gt;numeric-&gt;str and <code class="inline">ary</code> does not.</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
775
+ <div class="code"><pre>format = <span class="string"><span class="delimiter">&quot;</span><span class="content">c2x5CCxsdils_l_a6</span><span class="delimiter">&quot;</span></span>
776
+ ary = [<span class="integer">1</span>, <span class="integer">-100</span>, <span class="integer">127</span>, <span class="integer">128</span>, <span class="integer">32767</span>, <span class="float">987.654321098</span>/<span class="float">100.0</span>, <span class="integer">12345</span>, <span class="integer">123456</span>, <span class="integer">-32767</span>, <span class="integer">-123456</span>,
777
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">abcdef</span><span class="delimiter">&quot;</span></span>]
778
+ </pre></div>
779
+ </div>
780
+ <div class="anchor" id="bug12"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">12</span> <code class="inline">ary.<span class="bold">pack</span>(format) <span class="verification">!~</span><span class="verification"> /def/</span></code></div><ul><li><code class="inline">pack</code>: <span class="dev-text bug">The receiver of verification <code class="inline">!~</code> is <code class="inline">&quot;\x01\x9C\x00\x00\x00\x00\x00\x7F\x80\x00\xFF\x7F&gt;a\x91E\xCA\xC0\#@90\x00\x00@\xE2\x01\x00\x01\x80\xC0\x1D\xFE\xFF\xFF\xFF\xFF\xFFabcdef&quot;</code>.</span></li></ul></div><div class="anchor" id="success402"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">402</span> <code class="inline">RETURN<span class="verification">.</span><span class="verification">unpack</span><span class="verification">(format)</span><span class="verification">.</span><span class="verification">length</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> ary.length</span></code></div></div><div class="anchor" id="success403"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">403</span> <code class="inline">RETURN<span class="verification">.</span><span class="verification">unpack</span><span class="verification">(format)</span><span class="verification">.</span><span class="verification">join</span><span class="verification">(&quot;:&quot;)</span> <span class="verification">==</span><span class="verification"> ary.join(&quot;:&quot;)</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature67"><span class="anchor" id="public55"><span class="tag public">public</span></span> <span class="anchor" id="instance52"><span class="tag instance">52</span></span> Array#<span class="feature-name">permutation</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">permutation</code></li></ul></div></div><div class="user-item"><div class="p">The implementation makes no guarantees about the order in which the permutations are yielded.</div><span class="head">Usage</span> <code class="inline">(n){|p| block}</code> → Array<div class="p">Yields all permutations of length <code class="inline">n</code> of the elements of the array, then return the array itself.</div><span class="head">Usage</span> <code class="inline">{|p| block}</code> → Array<div class="p">Yields all permutations of all elements.</div><span class="head">Usage</span> <code class="inline">(n)</code> → Enumerator<span class="head">Usage</span> <code class="inline"></code> → Enumerator<div class="p">Examples:</div><div class="CodeRay">
781
+ <div class="code"><pre>a = [<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>]
782
+ a.permutation.to_a <span class="comment">#=&gt; [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]</span>
783
+ a.permutation(<span class="integer">1</span>).to_a <span class="comment">#=&gt; [[1],[2],[3]]</span>
784
+ a.permutation(<span class="integer">2</span>).to_a <span class="comment">#=&gt; [[1,2],[1,3],[2,1],[2,3],[3,1],[3,2]]</span>
785
+ a.permutation(<span class="integer">3</span>).to_a <span class="comment">#=&gt; [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]</span>
786
+ a.permutation(<span class="integer">0</span>).to_a <span class="comment">#=&gt; [[]] # one permutation of length 0</span>
787
+ a.permutation(<span class="integer">4</span>).to_a <span class="comment">#=&gt; [] # no permutations of length 4</span>
788
+ </pre></div>
789
+ </div>
790
+ </div><div class="dev-item"><div class="p"><span class="head">Test 68.</span> ruby/test/ruby/test_array.rb:test_permutation</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
791
+ <div class="code"><pre>a = <span class="constant">Array</span>[<span class="integer">1</span>,<span class="integer">2</span>,<span class="integer">3</span>]</pre></div>
792
+ </div>
793
+ <div class="anchor" id="success404"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">404</span> <code class="inline">a.<span class="bold">permutation</span>(0)<span class="verification">.</span><span class="verification">to_a</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> [[]]</span></code></div></div><div class="anchor" id="success405"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">405</span> <code class="inline">a.<span class="bold">permutation</span>(1)<span class="verification">.</span><span class="verification">to_a</span><span class="verification"></span><span class="verification">.</span><span class="verification">sort</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> [[1], [2], [3]]</span></code></div></div><div class="anchor" id="success406"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">406</span> <code class="inline">a.<span class="bold">permutation</span>(2)<span class="verification">.</span><span class="verification">to_a</span><span class="verification"></span><span class="verification">.</span><span class="verification">sort</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> [[1, 2], [1, 3], [2, 1], [2, 3], [3, 1], [3, 2]]</span></code></div></div><div class="anchor" id="success407"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">407</span> <code class="inline">a.<span class="bold">permutation</span>(3)<span class="verification">.</span><span class="verification">sort</span><span class="verification"></span><span class="verification">.</span><span class="verification">to_a</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]</span></code></div></div><div class="anchor" id="success408"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">408</span> <code class="inline">a.<span class="bold">permutation</span>(4)<span class="verification">.</span><span class="verification">to_a</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="anchor" id="success409"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">409</span> <code class="inline">a.<span class="bold">permutation</span>(-1)<span class="verification">.</span><span class="verification">to_a</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
794
+ <div class="code"><pre>a = <span class="string"><span class="delimiter">&quot;</span><span class="content">edcba</span><span class="delimiter">&quot;</span></span>.each_char.to_a</pre></div>
795
+ </div>
796
+ <div class="anchor" id="success410"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">410</span> <code class="inline">a.<span class="bold">permutation</span>(5)<span class="verification">.</span><span class="verification">sort</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> &apos;abcde&apos;.each_char.to_a.permutation(5).sort</span></code></div></div><div class="anchor" id="success411"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">411</span> <code class="inline">[].<span class="bold">permutation</span>(0)<span class="verification">.</span><span class="verification">to_a</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> [[]]</span></code></div></div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
797
+ <div class="code"><pre>a = <span class="constant">Array</span>[<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>, <span class="integer">4</span>]
798
+ b = <span class="constant">Array</span>[]
799
+ </pre></div>
800
+ </div>
801
+ <div class="anchor" id="bug13"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">13</span> <code class="inline">a.<span class="bold">permutation</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:1649)} <span class="verification">==</span><span class="verification"> [9, 8, 7, 6]</span></code></div><ul><li><code class="inline">permutation</code>: <span class="dev-text bug">The receiver of verification <code class="inline">==</code> is <code class="inline">[1, 2, 3, 4]</code>.</span></li></ul></div><div class="anchor" id="bug14"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">14</span> <code class="inline">[1, 2, 3, 4].<span class="bold">permutation</span><span class="verification">.</span><span class="verification">to_a</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> b</span></code></div><ul><li><code class="inline">permutation</code>: <span class="dev-text bug">The receiver of verification <code class="inline">==</code> is <code class="inline">[[1, 2, 3, 4], [1, 2, 4, 3], [1, 3, 2, 4], [1, 3, 4, 2], [1, 4, 2, 3], [1, 4, 3, 2], [2, 1, 3, 4], [2, 1, 4, 3], [2, 3, 1, 4], [2, 3, 4, 1], [2, 4, 1, 3], [2, 4, 3, 1], [3, 1, 2, 4], [3, 1, 4, 2], [3, 2, 1, 4], [3, 2, 4, 1], [3, 4, 1, 2], [3, 4, 2, 1], [4, 1, 2, 3], [4, 1, 3, 2], [4, 2, 1, 3], [4, 2, 3, 1], [4, 3, 1, 2], [4, 3, 2, 1]]</code>.</span></li></ul></div><div class="p"><span class="head">Test 68.1.</span> bug3708 ruby-dev:42067</div><div class="anchor" id="bug15"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">15</span> <code class="inline">[1, 2, 3, 4].<span class="bold">permutation</span><span class="verification">.</span><span class="verification">to_a</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> b</span></code></div><ul><li><code class="inline">permutation</code>: <span class="dev-text bug">The receiver of verification <code class="inline">==</code> is <code class="inline">[[1, 2, 3, 4], [1, 2, 4, 3], [1, 3, 2, 4], [1, 3, 4, 2], [1, 4, 2, 3], [1, 4, 3, 2], [2, 1, 3, 4], [2, 1, 4, 3], [2, 3, 1, 4], [2, 3, 4, 1], [2, 4, 1, 3], [2, 4, 3, 1], [3, 1, 2, 4], [3, 1, 4, 2], [3, 2, 1, 4], [3, 2, 4, 1], [3, 4, 1, 2], [3, 4, 2, 1], [4, 1, 2, 3], [4, 1, 3, 2], [4, 2, 1, 3], [4, 2, 3, 1], [4, 3, 1, 2], [4, 3, 2, 1]]</code>.</span></li></ul></div><div class="p"><span class="head">Test 69.</span> bug9932 ruby-core:63103 Bug #9932</div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature68"><span class="anchor" id="public56"><span class="tag public">public</span></span> <span class="anchor" id="instance53"><span class="tag instance">53</span></span> Array#<span class="feature-name">pop</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">pop</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">#push</code> for the opposite effect.</div><span class="head">Usage</span> <code class="inline"></code> → Object | <code class="inline">nil</code><div class="p">Removes the last element from <code class="inline">self</code> and returns it, or <code class="inline">nil</code> if the array is empty.</div><span class="head">Usage</span> <code class="inline">(n)</code> → Array<div class="p">Returns an array of the last <code class="inline">n</code> elements (or less) just like <code class="inline">array.slice!(-n, n)</code> does.</div><div class="CodeRay">
802
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">d</span><span class="delimiter">&quot;</span></span>]
803
+ a.pop <span class="comment">#=&gt; &quot;d&quot;</span>
804
+ a.pop(<span class="integer">2</span>) <span class="comment">#=&gt; [&quot;b&quot;, &quot;c&quot;]</span>
805
+ a <span class="comment">#=&gt; [&quot;a&quot;]</span>
806
+ </pre></div>
807
+ </div>
808
+ </div><div class="dev-item"><div class="p"><span class="head">Test 70.</span> ruby/test/ruby/test_array.rb:test_pop</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
809
+ <div class="code"><pre>a = <span class="constant">Array</span>[<span class="string"><span class="delimiter">&quot;</span><span class="content">cat</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">dog</span><span class="delimiter">&quot;</span></span>]</pre></div>
810
+ </div>
811
+ <div class="anchor" id="success412"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">412</span> <code class="inline">a.<span class="bold">pop</span> <span class="verification">==</span><span class="verification"> &quot;dog&quot;</span></code></div></div><div class="anchor" id="success413"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">413</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [&quot;cat&quot;]</span></code></div></div><div class="anchor" id="bug16"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">16</span> <code class="inline">a.<span class="bold">pop</span> <span class="verification">==</span><span class="verification"> &quot;cat&quot;</span></code></div><ul><li><code class="inline">pop</code>: <span class="dev-text bug">The receiver of verification <code class="inline">==</code> is <code class="inline">&quot;dog&quot;</code>.</span></li></ul></div><div class="anchor" id="bug17"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">17</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> []</span></code></div><ul><li><code class="inline">pop</code>: <span class="dev-text bug">The receiver of verification <code class="inline">==</code> is <code class="inline">[&quot;cat&quot;]</code>.</span></li></ul></div><div class="anchor" id="bug18"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">18</span> <code class="inline">a.<span class="bold">pop</span><span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div><ul><li><code class="inline">pop</code>: <span class="dev-text bug">The receiver of verification <code class="inline">nil?</code> is <code class="inline">&quot;dog&quot;</code>.</span></li></ul></div><div class="anchor" id="bug19"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">19</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> []</span></code></div><ul><li><code class="inline">pop</code>: <span class="dev-text bug">The receiver of verification <code class="inline">==</code> is <code class="inline">[&quot;cat&quot;]</code>.</span></li></ul></div><div class="p"><span class="head">Test 71.</span> ruby/test/ruby/test_array.rb:test_beg_end_0:5/6</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
812
+ <div class="code"><pre>x = [<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>, <span class="integer">4</span>, <span class="integer">5</span>]</pre></div>
813
+ </div>
814
+ <div class="anchor" id="success414"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">414</span> <code class="inline">x.<span class="bold">pop</span> <span class="verification">==</span><span class="verification"> 5</span></code></div></div><div class="anchor" id="bug20"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">20</span> <code class="inline">x.<span class="bold">pop</span>(2) <span class="verification">==</span><span class="verification"> [3, 4]</span></code></div><ul><li><code class="inline">pop</code>: <span class="dev-text bug">The receiver of verification <code class="inline">==</code> is <code class="inline">[4, 5]</code>.</span></li></ul></div><div class="anchor" id="bug21"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">21</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2]</span></code></div><ul><li><code class="inline">pop</code>: <span class="dev-text bug">The receiver of verification <code class="inline">==</code> is <code class="inline">[1, 2, 3]</code>.</span></li></ul></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature69"><span class="anchor" id="public57"><span class="tag public">public</span></span> <span class="anchor" id="instance54"><span class="tag instance">54</span></span> Array#<span class="feature-name">product</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">product</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline">(other_ary, ...)</code> → Array<div class="p">Returns an array of all combinations of elements from all arrays.</div><div class="p">The length of the returned array is the product of the length of <code class="inline">self</code> and the argument arrays.</div><span class="head">Usage</span> <code class="inline">(other_ary, ...){|p| block}</code> → Array<div class="p">Product will yield all combinations and return <code class="inline">self</code>.</div><div class="CodeRay">
815
+ <div class="code"><pre>[<span class="integer">1</span>,<span class="integer">2</span>,<span class="integer">3</span>].product([<span class="integer">4</span>,<span class="integer">5</span>]) <span class="comment">#=&gt; [[1,4],[1,5],[2,4],[2,5],[3,4],[3,5]]</span>
816
+ [<span class="integer">1</span>,<span class="integer">2</span>].product([<span class="integer">1</span>,<span class="integer">2</span>]) <span class="comment">#=&gt; [[1,1],[1,2],[2,1],[2,2]]</span>
817
+ [<span class="integer">1</span>,<span class="integer">2</span>].product([<span class="integer">3</span>,<span class="integer">4</span>],[<span class="integer">5</span>,<span class="integer">6</span>]) <span class="comment">#=&gt; [[1,3,5],[1,3,6],[1,4,5],[1,4,6],</span>
818
+ <span class="comment"># [2,3,5],[2,3,6],[2,4,5],[2,4,6]]</span>
819
+ [<span class="integer">1</span>,<span class="integer">2</span>].product() <span class="comment">#=&gt; [[1],[2]]</span>
820
+ [<span class="integer">1</span>,<span class="integer">2</span>].product([]) <span class="comment">#=&gt; []</span>
821
+ </pre></div>
822
+ </div>
823
+ </div><div class="dev-item"><div class="p"><span class="head">Test 72.</span> ruby/test/ruby/test_array.rb:test_product</div><div class="anchor" id="success415"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">415</span> <code class="inline">[1, 2, 3].<span class="bold">product</span>([4, 5]) <span class="verification">==</span><span class="verification"> [[1, 4], [1, 5], [2, 4], [2, 5], [3, 4], [3, 5]]</span></code></div></div><div class="anchor" id="success416"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">416</span> <code class="inline">[1, 2].<span class="bold">product</span>([1, 2]) <span class="verification">==</span><span class="verification"> [[1, 1], [1, 2], [2, 1], [2, 2]]</span></code></div></div><div class="anchor" id="success417"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">417</span> <code class="inline">[1, 2].<span class="bold">product</span>([3, 4], [5, 6]) <span class="verification">==</span><span class="verification"> [[1, 3, 5], [1, 3, 6], [1, 4, 5], [1, 4, 6], [2, 3, 5], [2, 3, 6], [2, 4, 5], [2, 4, 6]]</span></code></div></div><div class="anchor" id="success418"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">418</span> <code class="inline">[1, 2].<span class="bold">product</span> <span class="verification">==</span><span class="verification"> [[1], [2]]</span></code></div></div><div class="anchor" id="success419"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">419</span> <code class="inline">[1, 2].<span class="bold">product</span>([]) <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="p"><span class="head">Test 72.1.</span> bug3394 = ruby-dev:41540</div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature70"><span class="anchor" id="public58"><span class="tag public">public</span></span> <span class="anchor" id="instance55"><span class="tag instance">55</span></span> Array#<span class="feature-name">push</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">push</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">#pop</code> for the opposite effect.</div><span class="head">Usage</span> <code class="inline">(obj, ...)</code> → Array<div class="p">Append — Pushes the given object(s) on to the end of this array. This expression returns the array itself, so several appends may be chained together.</div><div class="CodeRay">
824
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>]
825
+ a.push(<span class="string"><span class="delimiter">&quot;</span><span class="content">d</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">e</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">f</span><span class="delimiter">&quot;</span></span>)
826
+ <span class="comment">#=&gt; [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;e&quot;, &quot;f&quot;]</span>
827
+ [<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>,].push(<span class="integer">4</span>).push(<span class="integer">5</span>)
828
+ <span class="comment">#=&gt; [1, 2, 3, 4, 5]</span>
829
+ </pre></div>
830
+ </div>
831
+ </div><div class="dev-item"><div class="p"><span class="head">Test 73.</span> ruby/test/ruby/test_array.rb:test_push</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
832
+ <div class="code"><pre>a = <span class="constant">Array</span>[<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>]</pre></div>
833
+ </div>
834
+ <div class="anchor" id="success420"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">420</span> <code class="inline">a.<span class="bold">push</span>(4, 5) <span class="verification">==</span><span class="verification"> [1, 2, 3, 4, 5]</span></code></div></div><div class="anchor" id="bug22"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">22</span> <code class="inline">a.<span class="bold">push</span>(nil) <span class="verification">==</span><span class="verification"> [1, 2, 3, 4, 5, nil]</span></code></div><ul><li><code class="inline">push</code>: <span class="dev-text bug">The receiver of verification <code class="inline">==</code> is <code class="inline">[1, 2, 3, nil]</code>.</span></li></ul></div><div class="anchor" id="success421"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">421</span> <code class="inline">a.<span class="bold">push</span><span class="verification">.</span><span class="verification">succeed?</span><span class="verification"></span></code></div></div><div class="anchor" id="bug23"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">23</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2, 3, 4, 5, nil]</span></code></div><ul><li><code class="inline">push</code>: <span class="dev-text bug">The receiver of verification <code class="inline">==</code> is <code class="inline">[1, 2, 3]</code>.</span></li></ul></div><div class="anchor" id="success422"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">422</span> <code class="inline">a.<span class="bold">push</span>(6, 7)<span class="verification">.</span><span class="verification">succeed?</span><span class="verification"></span></code></div></div><div class="anchor" id="bug24"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">24</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2, 3, 4, 5, nil, 6, 7]</span></code></div><ul><li><code class="inline">push</code>: <span class="dev-text bug">The receiver of verification <code class="inline">==</code> is <code class="inline">[1, 2, 3, 6, 7]</code>.</span></li></ul></div><div class="p"><span class="head">Test 74.</span> ruby/test/ruby/test_array.rb:test_beg_end_0:6/6</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
835
+ <div class="code"><pre>x = [<span class="integer">1</span>, <span class="integer">2</span>]</pre></div>
836
+ </div>
837
+ <div class="anchor" id="success423"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">423</span> <code class="inline">x.<span class="bold">push</span>(3, 4) <span class="verification">==</span><span class="verification"> [1, 2, 3, 4]</span></code></div></div><div class="anchor" id="bug25"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">25</span> <code class="inline">x.<span class="bold">push</span>(5) <span class="verification">==</span><span class="verification"> [1, 2, 3, 4, 5]</span></code></div><ul><li><code class="inline">push</code>: <span class="dev-text bug">The receiver of verification <code class="inline">==</code> is <code class="inline">[1, 2, 5]</code>.</span></li></ul></div><div class="anchor" id="bug26"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">26</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2, 3, 4, 5]</span></code></div><ul><li><code class="inline">push</code>: <span class="dev-text bug">The receiver of verification <code class="inline">==</code> is <code class="inline">[1, 2, 5]</code>.</span></li></ul></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature71"><span class="anchor" id="public59"><span class="tag public">public</span></span> <span class="anchor" id="instance56"><span class="tag instance">56</span></span> Array#<span class="feature-name">rassoc</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">rassoc</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">delete_if</code>.</div><span class="head">Usage</span> <code class="inline">(obj)</code> → Array | <code class="inline">nil</code><div class="p">Searches through the array whose elements are also arrays.</div><div class="p">Compares <code class="inline">obj</code> with the second element of each contained array using <code class="inline">obj.==</code>.</div><div class="p">Returns the first contained array that matches <code class="inline">obj</code>.</div><div class="CodeRay">
838
+ <div class="code"><pre>a = [[<span class="integer">1</span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">one</span><span class="delimiter">&quot;</span></span>], [<span class="integer">2</span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">two</span><span class="delimiter">&quot;</span></span>], [<span class="integer">3</span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">three</span><span class="delimiter">&quot;</span></span>], [<span class="string"><span class="delimiter">&quot;</span><span class="content">ii</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">two</span><span class="delimiter">&quot;</span></span>]]
839
+ a.rassoc(<span class="string"><span class="delimiter">&quot;</span><span class="content">two</span><span class="delimiter">&quot;</span></span>) <span class="comment">#=&gt; [2, &quot;two&quot;]</span>
840
+ a.rassoc(<span class="string"><span class="delimiter">&quot;</span><span class="content">four</span><span class="delimiter">&quot;</span></span>) <span class="comment">#=&gt; nil</span>
841
+ </pre></div>
842
+ </div>
843
+ </div><div class="dev-item"><div class="p"><span class="head">Test 75.</span> ruby/test/ruby/test_array.rb:test_rassoc</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
844
+ <div class="code"><pre>a1 = <span class="constant">Array</span>[*<span class="string"><span class="delimiter">%w(</span><span class="content">cat feline</span><span class="delimiter">)</span></span>]
845
+ a2 = <span class="constant">Array</span>[*<span class="string"><span class="delimiter">%w(</span><span class="content">dog canine</span><span class="delimiter">)</span></span>]
846
+ a3 = <span class="constant">Array</span>[*<span class="string"><span class="delimiter">%w(</span><span class="content">mule asinine</span><span class="delimiter">)</span></span>]
847
+ a = <span class="constant">Array</span>[a1, a2, a3]
848
+ </pre></div>
849
+ </div>
850
+ <div class="anchor" id="success424"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">424</span> <code class="inline">a.<span class="bold">rassoc</span>(&quot;feline&quot;) <span class="verification">==</span><span class="verification"> a1</span></code></div></div><div class="anchor" id="success425"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">425</span> <code class="inline">a.<span class="bold">rassoc</span>(&quot;asinine&quot;) <span class="verification">==</span><span class="verification"> a3</span></code></div></div><div class="anchor" id="success426"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">426</span> <code class="inline">a.<span class="bold">rassoc</span>(&quot;dog&quot;)<span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="anchor" id="success427"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">427</span> <code class="inline">a.<span class="bold">rassoc</span>(&quot;mule&quot;)<span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="anchor" id="success428"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">428</span> <code class="inline">a.<span class="bold">rassoc</span>(1..2)<span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature72"><span class="anchor" id="public60"><span class="tag public">public</span></span> <span class="anchor" id="instance57"><span class="tag instance">57</span></span> Array#<span class="feature-name">reject</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">reject</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">#delete_if</code></div><span class="head">Usage</span> <code class="inline">{|item| block}</code> → Array<div class="p">Returns a new array containing the items in <code class="inline">self</code> for which the given block is not true.</div><span class="head">Usage</span> <code class="inline"></code> → Enumerator</div><div class="dev-item"><div class="p"><span class="head">Test 76.</span> ruby/test/ruby/test_array.rb:test_reject</div><div class="anchor" id="success429"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">429</span> <code class="inline">[0, 1, 2, 3].<span class="bold">reject</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:1778)} <span class="verification">==</span><span class="verification"> [1, 3]</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature73"><span class="anchor" id="public61"><span class="tag public">public</span></span> <span class="anchor" id="instance58"><span class="tag instance">58</span></span> Array#<span class="feature-name">reject!</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">reject!</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">Enumerable#reject</code> and <code class="inline">#delete_if</code>.</div><span class="head">Usage</span> <code class="inline">{|item| block}</code> → Array<div class="p">Equivalent to <code class="inline">#delete_if</code>, deleting elements from <code class="inline">self</code> for which the block evaluates to <code class="inline">true</code>, but returns <code class="inline">nil</code> if no changes were made.</div><div class="p">The array is changed instantly every time the block is called, not after the iteration is over.</div><span class="head">Usage</span> <code class="inline">{|item| block}</code> → NilClass<span class="head">Usage</span> <code class="inline"></code> → Enumerator</div><div class="dev-item"><div class="p"><span class="head">Test 77.</span> ruby/test/ruby/test_array.rb:test_reject!</div><div class="anchor" id="success430"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">430</span> <code class="inline">[1, 2, 3, 4, 5].<span class="bold">reject!</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:1788)}<span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="anchor" id="success431"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">431</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2, 3, 4, 5]</span></code></div></div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
851
+ <div class="code"><pre>a = <span class="constant">Array</span>[<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>, <span class="integer">4</span>, <span class="integer">5</span>]</pre></div>
852
+ </div>
853
+ <div class="anchor" id="success432"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">432</span> <code class="inline">a.<span class="bold">reject!</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:1791)} <span class="verification">==</span><span class="verification"> a</span></code></div></div><div class="anchor" id="success433"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">433</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
854
+ <div class="code"><pre>a = <span class="constant">Array</span>[<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>, <span class="integer">4</span>, <span class="integer">5</span>]</pre></div>
855
+ </div>
856
+ <div class="anchor" id="success434"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">434</span> <code class="inline">a.<span class="bold">reject!</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:1794)} <span class="verification">==</span><span class="verification"> a</span></code></div></div><div class="anchor" id="success435"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">435</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2, 3]</span></code></div></div><div class="p"><span class="head">Test 77.1.</span> bug2545 ruby-core:27366</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
857
+ <div class="code"><pre>a = <span class="constant">Array</span>[<span class="integer">5</span>, <span class="integer">6</span>, <span class="integer">7</span>, <span class="integer">8</span>, <span class="integer">9</span>, <span class="integer">10</span>]</pre></div>
858
+ </div>
859
+ <div class="anchor" id="bug27"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">27</span> <code class="inline">a.<span class="bold">reject!</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:1798)} <span class="verification">==</span><span class="verification"> 9</span></code></div><ul><li><code class="inline">reject!</code>: <span class="dev-text bug">LocalJumpError. Break from proc-closure.</span><table class="backtrace"><colgroup><col /><col /></colgroup><tbody><tr><td><code>spec:1798</code></td><td><code class="inline"></code></td></tr></tbody></table></li></ul></div><div class="anchor" id="untestable2"><div class="indent dev-text untestable p"><span class="hang-indent">​</span><span class="tag untestable">2</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [7, 8, 9, 10]</span></code></div><div class="p indent"><span class="dev-text untestable">Missing a preceding successful unit test.</span></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature74"><span class="anchor" id="public62"><span class="tag public">public</span></span> <span class="anchor" id="instance59"><span class="tag instance">59</span></span> Array#<span class="feature-name">repeated_combination</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">repeated_combination</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline">(n){|c| block}</code> → Array<div class="p">When invoked with a block, yields all repeated combinations of length <code class="inline">n</code> of elements from the array and then returns the array itself.</div><div class="p">The implementation makes no guarantees about the order in which the repeated combinations are yielded.</div><span class="head">Usage</span> <code class="inline">(n)</code> → Enumerator<div class="p">If no block is given, an <code class="inline">Enumerator</code> is returned instead.</div><div class="p">Examples:</div><div class="CodeRay">
860
+ <div class="code"><pre>a = [<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>]
861
+ a.repeated_combination(<span class="integer">1</span>).to_a <span class="comment">#=&gt; [[1], [2], [3]]</span>
862
+ a.repeated_combination(<span class="integer">2</span>).to_a <span class="comment">#=&gt; [[1,1],[1,2],[1,3],[2,2],[2,3],[3,3]]</span>
863
+ a.repeated_combination(<span class="integer">3</span>).to_a <span class="comment">#=&gt; [[1,1,1],[1,1,2],[1,1,3],[1,2,2],[1,2,3],</span>
864
+ <span class="comment"># [1,3,3],[2,2,2],[2,2,3],[2,3,3],[3,3,3]]</span>
865
+ a.repeated_combination(<span class="integer">4</span>).to_a <span class="comment">#=&gt; [[1,1,1,1],[1,1,1,2],[1,1,1,3],[1,1,2,2],[1,1,2,3],</span>
866
+ <span class="comment"># [1,1,3,3],[1,2,2,2],[1,2,2,3],[1,2,3,3],[1,3,3,3],</span>
867
+ <span class="comment"># [2,2,2,2],[2,2,2,3],[2,2,3,3],[2,3,3,3],[3,3,3,3]]</span>
868
+ a.repeated_combination(<span class="integer">0</span>).to_a <span class="comment">#=&gt; [[]] # one combination of length 0</span>
869
+ </pre></div>
870
+ </div>
871
+ </div><div class="dev-item"><div class="p indent anchor" id="missing_test14"><span class="hang-indent">​</span><span class="tag missing_test">Missing test</span><span class="dev-text missing_test"> Not unit tested.</span></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature75"><span class="anchor" id="public63"><span class="tag public">public</span></span> <span class="anchor" id="instance60"><span class="tag instance">60</span></span> Array#<span class="feature-name">repeated_permutation</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">repeated_permutation</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline">(n){|p| block}</code> → Array<div class="p">When invoked with a block, yield all repeated permutations of length <code class="inline">n</code> of the elements of the array, then return the array itself.</div><div class="p">The implementation makes no guarantees about the order in which the repeated permutations are yielded.</div><span class="head">Usage</span> <code class="inline">(n)</code> → Enumerator<div class="p">Examples:</div><div class="CodeRay">
872
+ <div class="code"><pre>a = [<span class="integer">1</span>, <span class="integer">2</span>]
873
+ a.repeated_permutation(<span class="integer">1</span>).to_a <span class="comment">#=&gt; [[1], [2]]</span>
874
+ a.repeated_permutation(<span class="integer">2</span>).to_a <span class="comment">#=&gt; [[1,1],[1,2],[2,1],[2,2]]</span>
875
+ a.repeated_permutation(<span class="integer">3</span>).to_a <span class="comment">#=&gt; [[1,1,1],[1,1,2],[1,2,1],[1,2,2],</span>
876
+ <span class="comment"># [2,1,1],[2,1,2],[2,2,1],[2,2,2]]</span>
877
+ a.repeated_permutation(<span class="integer">0</span>).to_a <span class="comment">#=&gt; [[]] # one permutation of length 0</span>
878
+ </pre></div>
879
+ </div>
880
+ </div><div class="dev-item"><div class="p indent anchor" id="missing_test15"><span class="hang-indent">​</span><span class="tag missing_test">Missing test</span><span class="dev-text missing_test"> Not unit tested.</span></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature76"><span class="anchor" id="public64"><span class="tag public">public</span></span> <span class="anchor" id="instance61"><span class="tag instance">61</span></span> Array#<span class="feature-name">replace</span> (alias: <span class="feature-name">initialize_copy</span>)</h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">replace</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline">(other_ary)</code> → Array<div class="p">Replaces the contents of <code class="inline">self</code> with the contents of <code class="inline">other_ary</code>, truncating or expanding if necessary.</div><div class="CodeRay">
881
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">d</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">e</span><span class="delimiter">&quot;</span></span>]
882
+ a.replace([<span class="string"><span class="delimiter">&quot;</span><span class="content">x</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">y</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">z</span><span class="delimiter">&quot;</span></span>]) <span class="comment">#=&gt; [&quot;x&quot;, &quot;y&quot;, &quot;z&quot;]</span>
883
+ a <span class="comment">#=&gt; [&quot;x&quot;, &quot;y&quot;, &quot;z&quot;]</span>
884
+ </pre></div>
885
+ </div>
886
+ </div><div class="dev-item"><div class="p"><span class="head">Test 78.</span> ruby/test/ruby/test_array.rb:test_replace_shared_ary</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
887
+ <div class="code"><pre>a = [<span class="integer">1</span>] * <span class="integer">100</span>
888
+ b = []
889
+ </pre></div>
890
+ </div>
891
+ <div class="anchor" id="bad_test1"><div class="indent dev-text bad_test p"><span class="hang-indent">​</span><span class="tag bad_test">1</span> <code class="inline">b.<span class="bold">replace</span>(a)</code></div><div class="p indent"><span class="dev-text bad_test">Missing a verification.</span></div></div><div class="anchor" id="success436"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">436</span> <code class="inline">a.<span class="bold">replace</span>([1, 2, 3])<span class="verification">.</span><span class="verification">succeed?</span><span class="verification"></span></code></div></div><div class="anchor" id="success437"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">437</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2, 3]</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature77"><span class="anchor" id="public65"><span class="tag public">public</span></span> <span class="anchor" id="instance62"><span class="tag instance">62</span></span> Array#<span class="feature-name">reverse</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">reverse</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline"></code> → Array<div class="p">Returns a new array containing <code class="inline">self</code>‘s elements in reverse order.</div><div class="CodeRay">
892
+ <div class="code"><pre>[<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>].reverse <span class="comment">#=&gt; [&quot;c&quot;, &quot;b&quot;, &quot;a&quot;]</span>
893
+ [<span class="integer">1</span>].reverse <span class="comment">#=&gt; [1]</span>
894
+ </pre></div>
895
+ </div>
896
+ </div><div class="dev-item"><div class="p"><span class="head">Test 79.</span> ruby/test/ruby/test_array.rb:test_reverse</div><div class="anchor" id="success438"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">438</span> <code class="inline">[&quot;dog&quot;, &quot;cat&quot;, &quot;bee&quot;, &quot;ant&quot;].<span class="bold">reverse</span> <span class="verification">==</span><span class="verification"> [&quot;ant&quot;, &quot;bee&quot;, &quot;cat&quot;, &quot;dog&quot;]</span></code></div></div><div class="anchor" id="success439"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">439</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [&quot;dog&quot;, &quot;cat&quot;, &quot;bee&quot;, &quot;ant&quot;]</span></code></div></div><div class="anchor" id="success440"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">440</span> <code class="inline">[].<span class="bold">reverse</span> <span class="verification">==</span><span class="verification"> []</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature78"><span class="anchor" id="public66"><span class="tag public">public</span></span> <span class="anchor" id="instance63"><span class="tag instance">63</span></span> Array#<span class="feature-name">reverse!</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">reverse!</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline"></code> → Array<div class="p">Reverses <code class="inline">self</code> in place.</div><div class="CodeRay">
897
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>]
898
+ a.reverse! <span class="comment">#=&gt; [&quot;c&quot;, &quot;b&quot;, &quot;a&quot;]</span>
899
+ a <span class="comment">#=&gt; [&quot;c&quot;, &quot;b&quot;, &quot;a&quot;]</span>
900
+ </pre></div>
901
+ </div>
902
+ </div><div class="dev-item"><div class="p"><span class="head">Test 80.</span> ruby/test/ruby/test_array.rb:test_reverse!</div><div class="anchor" id="success441"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">441</span> <code class="inline">[&quot;dog&quot;, &quot;cat&quot;, &quot;bee&quot;, &quot;ant&quot;].<span class="bold">reverse!</span> <span class="verification">==</span><span class="verification"> [&quot;ant&quot;, &quot;bee&quot;, &quot;cat&quot;, &quot;dog&quot;]</span></code></div></div><div class="anchor" id="success442"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">442</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [&quot;ant&quot;, &quot;bee&quot;, &quot;cat&quot;, &quot;dog&quot;]</span></code></div></div><div class="p"><span class="head">Test 80.1.</span> Array#reverse always returns self.</div><div class="anchor" id="success443"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">443</span> <code class="inline">[].<span class="bold">reverse!</span> <span class="verification">==</span><span class="verification"> []</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature79"><span class="anchor" id="public67"><span class="tag public">public</span></span> <span class="anchor" id="instance64"><span class="tag instance">64</span></span> Array#<span class="feature-name">reverse_each</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">reverse_each</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline">{|item| block}</code> → Array<span class="head">Usage</span> <code class="inline"></code> → Enumerator<div class="p">Same as <code class="inline">#each</code>, but traverses <code class="inline">self</code> in reverse order.</div><div class="CodeRay">
903
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>]
904
+ a.reverse_each{|x| print x, <span class="string"><span class="delimiter">&quot;</span><span class="content"> </span><span class="delimiter">&quot;</span></span>}
905
+ </pre></div>
906
+ </div>
907
+ <div class="p">produces:</div><div class="CodeRay">
908
+ <div class="code"><pre>c b a
909
+ </pre></div>
910
+ </div>
911
+ </div><div class="dev-item"><div class="p indent anchor" id="missing_test16"><span class="hang-indent">​</span><span class="tag missing_test">Missing test</span><span class="dev-text missing_test"> Not unit tested.</span></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature80"><span class="anchor" id="public68"><span class="tag public">public</span></span> <span class="anchor" id="instance65"><span class="tag instance">65</span></span> Array#<span class="feature-name">rindex</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">rindex</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">#index</code>.</div><span class="head">Usage</span> <code class="inline">(obj)</code> → Integer | <code class="inline">nil</code><div class="p">Returns the index of the last object in <code class="inline">self</code> <code class="inline">==</code> to <code class="inline">obj</code>. Returns <code class="inline">nil</code> if no match is found.</div><span class="head">Usage</span> <code class="inline">{|item| block}</code> → Integer | <code class="inline">nil</code><div class="p">Returns the index of the first object for which the block returns true, starting from the last object.</div><span class="head">Usage</span> <code class="inline"></code> → Enumerator<div class="CodeRay">
912
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>]
913
+ a.rindex(<span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>) <span class="comment">#=&gt; 3</span>
914
+ a.rindex(<span class="string"><span class="delimiter">&quot;</span><span class="content">z</span><span class="delimiter">&quot;</span></span>) <span class="comment">#=&gt; nil</span>
915
+ a.rindex{|x| x == <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>} <span class="comment">#=&gt; 3</span>
916
+ </pre></div>
917
+ </div>
918
+ </div><div class="dev-item"><div class="p indent anchor" id="missing_test17"><span class="hang-indent">​</span><span class="tag missing_test">Missing test</span><span class="dev-text missing_test"> Not unit tested.</span></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature81"><span class="anchor" id="public69"><span class="tag public">public</span></span> <span class="anchor" id="instance66"><span class="tag instance">66</span></span> Array#<span class="feature-name">rotate</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">rotate</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline">(count=1)</code> → Array<div class="p">Returns a new array by rotating <code class="inline">self</code> so that the element at count is the first element of the new array.</div><div class="p">If count is negative then it rotates in the opposite direction, starting from the end of <code class="inline">self</code> where <code class="inline">-1</code> is the last element.</div><div class="CodeRay">
919
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">d</span><span class="delimiter">&quot;</span></span>]
920
+ a.rotate <span class="comment">#=&gt; [&quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;a&quot;]</span>
921
+ a <span class="comment">#=&gt; [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;]</span>
922
+ a.rotate(<span class="integer">2</span>) <span class="comment">#=&gt; [&quot;c&quot;, &quot;d&quot;, &quot;a&quot;, &quot;b&quot;]</span>
923
+ a.rotate(<span class="integer">-3</span>) <span class="comment">#=&gt; [&quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;a&quot;]</span>
924
+ </pre></div>
925
+ </div>
926
+ </div><div class="dev-item"><div class="p"><span class="head">Test 81.</span> ruby/test/ruby/test_array.rb:test_rotate</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
927
+ <div class="code"><pre>a = [<span class="integer">1</span>,<span class="integer">2</span>,<span class="integer">3</span>,<span class="integer">4</span>,<span class="integer">5</span>]</pre></div>
928
+ </div>
929
+ <div class="anchor" id="success444"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">444</span> <code class="inline">a.<span class="bold">rotate</span> <span class="verification">==</span><span class="verification"> [2, 3, 4, 5, 1]</span></code></div></div><div class="anchor" id="success445"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">445</span> <code class="inline">a.<span class="bold">rotate</span>(-1) <span class="verification">==</span><span class="verification"> [5, 1, 2, 3, 4]</span></code></div></div><div class="anchor" id="success446"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">446</span> <code class="inline">a.<span class="bold">rotate</span>(2) <span class="verification">==</span><span class="verification"> [3, 4, 5, 1, 2]</span></code></div></div><div class="anchor" id="success447"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">447</span> <code class="inline">a.<span class="bold">rotate</span>(-2) <span class="verification">==</span><span class="verification"> [4, 5, 1, 2, 3]</span></code></div></div><div class="anchor" id="success448"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">448</span> <code class="inline">a.<span class="bold">rotate</span>(13) <span class="verification">==</span><span class="verification"> [4, 5, 1, 2, 3]</span></code></div></div><div class="anchor" id="success449"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">449</span> <code class="inline">a.<span class="bold">rotate</span>(-13) <span class="verification">==</span><span class="verification"> [3, 4, 5, 1, 2]</span></code></div></div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
930
+ <div class="code"><pre>a = [<span class="integer">1</span>]</pre></div>
931
+ </div>
932
+ <div class="anchor" id="success450"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">450</span> <code class="inline">a.<span class="bold">rotate</span> <span class="verification">==</span><span class="verification"> [1]</span></code></div></div><div class="anchor" id="success451"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">451</span> <code class="inline">a.<span class="bold">rotate</span>(2) <span class="verification">==</span><span class="verification"> [1]</span></code></div></div><div class="anchor" id="success452"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">452</span> <code class="inline">a.<span class="bold">rotate</span>(-4) <span class="verification">==</span><span class="verification"> [1]</span></code></div></div><div class="anchor" id="success453"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">453</span> <code class="inline">a.<span class="bold">rotate</span>(13) <span class="verification">==</span><span class="verification"> [1]</span></code></div></div><div class="anchor" id="success454"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">454</span> <code class="inline">a.<span class="bold">rotate</span>(-13) <span class="verification">==</span><span class="verification"> [1]</span></code></div></div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
933
+ <div class="code"><pre>a = []</pre></div>
934
+ </div>
935
+ <div class="anchor" id="success455"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">455</span> <code class="inline">a.<span class="bold">rotate</span> <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="anchor" id="success456"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">456</span> <code class="inline">a.<span class="bold">rotate</span>(2) <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="anchor" id="success457"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">457</span> <code class="inline">a.<span class="bold">rotate</span>(-4) <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="anchor" id="success458"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">458</span> <code class="inline">a.<span class="bold">rotate</span>(13) <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="anchor" id="success459"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">459</span> <code class="inline">a.<span class="bold">rotate</span>(-13) <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="anchor" id="success460"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">460</span> <code class="inline">[1, 2, 3].<span class="bold">rotate</span>(1, 1)<span class="verification">.</span><span class="verification">raise?</span><span class="verification">(ArgumentError)</span></code></div></div><div class="anchor" id="success461"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">461</span> <code class="inline">[1, 2, 3, 4, 5].<span class="bold">rotate</span>(2147483647.9) <span class="verification">==</span><span class="verification"> [3, 4, 5, 1, 2]</span></code></div></div><div class="anchor" id="success462"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">462</span> <code class="inline">[1, 2, 3, 4, 5].<span class="bold">rotate</span>(-2147483648.9) <span class="verification">==</span><span class="verification"> [3, 4, 5, 1, 2]</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature82"><span class="anchor" id="public70"><span class="tag public">public</span></span> <span class="anchor" id="instance67"><span class="tag instance">67</span></span> Array#<span class="feature-name">rotate!</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">rotate!</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline">(count=1)</code> → Array<div class="p">Rotates <code class="inline">self</code> in place so that the element at count comes first, and returns <code class="inline">self</code>.</div><div class="p">If count is negative, then it rotates in the opposite direction, starting from the end of the array where <code class="inline">-1</code> is the last element.</div><div class="CodeRay">
936
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">d</span><span class="delimiter">&quot;</span></span>]
937
+ a.rotate! <span class="comment">#=&gt; [&quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;a&quot;]</span>
938
+ a <span class="comment">#=&gt; [&quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;a&quot;]</span>
939
+ a.rotate!(<span class="integer">2</span>) <span class="comment">#=&gt; [&quot;d&quot;, &quot;a&quot;, &quot;b&quot;, &quot;c&quot;]</span>
940
+ a.rotate!(<span class="integer">-3</span>) <span class="comment">#=&gt; [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;]</span>
941
+ </pre></div>
942
+ </div>
943
+ </div><div class="dev-item"><div class="p"><span class="head">Test 82.</span> ruby/test/ruby/test_array.rb:test_rotate!</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
944
+ <div class="code"><pre>a = [<span class="integer">1</span>,<span class="integer">2</span>,<span class="integer">3</span>,<span class="integer">4</span>,<span class="integer">5</span>]</pre></div>
945
+ </div>
946
+ <div class="anchor" id="success463"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">463</span> <code class="inline">a.<span class="bold">rotate!</span> <span class="verification">==</span><span class="verification"> [2, 3, 4, 5, 1]</span></code></div></div><div class="anchor" id="success464"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">464</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [2, 3, 4, 5, 1]</span></code></div></div><div class="anchor" id="bug28"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">28</span> <code class="inline">a.<span class="bold">rotate!</span>(2) <span class="verification">==</span><span class="verification"> [4, 5, 1, 2, 3]</span></code></div><ul><li><code class="inline">rotate!</code>: <span class="dev-text bug">The receiver of verification <code class="inline">==</code> is <code class="inline">[3, 4, 5, 1, 2]</code>.</span></li></ul></div><div class="anchor" id="bug29"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">29</span> <code class="inline">a.<span class="bold">rotate!</span>(-4) <span class="verification">==</span><span class="verification"> [5, 1, 2, 3, 4]</span></code></div><ul><li><code class="inline">rotate!</code>: <span class="dev-text bug">The receiver of verification <code class="inline">==</code> is <code class="inline">[2, 3, 4, 5, 1]</code>.</span></li></ul></div><div class="anchor" id="bug30"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">30</span> <code class="inline">a.<span class="bold">rotate!</span>(13) <span class="verification">==</span><span class="verification"> [3, 4, 5, 1, 2]</span></code></div><ul><li><code class="inline">rotate!</code>: <span class="dev-text bug">The receiver of verification <code class="inline">==</code> is <code class="inline">[4, 5, 1, 2, 3]</code>.</span></li></ul></div><div class="anchor" id="bug31"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">31</span> <code class="inline">a.<span class="bold">rotate!</span>(-13) <span class="verification">==</span><span class="verification"> [5, 1, 2, 3, 4]</span></code></div><ul><li><code class="inline">rotate!</code>: <span class="dev-text bug">The receiver of verification <code class="inline">==</code> is <code class="inline">[3, 4, 5, 1, 2]</code>.</span></li></ul></div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
947
+ <div class="code"><pre>a = [<span class="integer">1</span>]</pre></div>
948
+ </div>
949
+ <div class="anchor" id="success465"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">465</span> <code class="inline">a.<span class="bold">rotate!</span> <span class="verification">==</span><span class="verification"> [1]</span></code></div></div><div class="anchor" id="success466"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">466</span> <code class="inline">a.<span class="bold">rotate!</span>(2) <span class="verification">==</span><span class="verification"> [1]</span></code></div></div><div class="anchor" id="success467"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">467</span> <code class="inline">a.<span class="bold">rotate!</span>(-4) <span class="verification">==</span><span class="verification"> [1]</span></code></div></div><div class="anchor" id="success468"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">468</span> <code class="inline">a.<span class="bold">rotate!</span>(13) <span class="verification">==</span><span class="verification"> [1]</span></code></div></div><div class="anchor" id="success469"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">469</span> <code class="inline">a.<span class="bold">rotate!</span>(-13) <span class="verification">==</span><span class="verification"> [1]</span></code></div></div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
950
+ <div class="code"><pre>a = []</pre></div>
951
+ </div>
952
+ <div class="anchor" id="success470"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">470</span> <code class="inline">a.<span class="bold">rotate!</span> <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="anchor" id="success471"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">471</span> <code class="inline">a.<span class="bold">rotate!</span>(2) <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="anchor" id="success472"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">472</span> <code class="inline">a.<span class="bold">rotate!</span>(-4) <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="anchor" id="success473"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">473</span> <code class="inline">a.<span class="bold">rotate!</span>(13) <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="anchor" id="success474"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">474</span> <code class="inline">a.<span class="bold">rotate!</span>(-13) <span class="verification">==</span><span class="verification"> []</span></code></div></div><div class="anchor" id="bug32"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">32</span> <code class="inline">[].<span class="bold">rotate!</span><span class="verification">.</span><span class="verification">raise?</span><span class="verification">(RuntimeError, message: /can\&apos;t modify frozen/)</span></code></div><ul><li><code class="inline">rotate!</code>: <span class="dev-text bug">Did not raise an exception.</span></li></ul></div><div class="anchor" id="success475"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">475</span> <code class="inline">[1, 2, 3].<span class="bold">rotate!</span>(1, 1)<span class="verification">.</span><span class="verification">raise?</span><span class="verification">(ArgumentError)</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature83"><span class="anchor" id="public71"><span class="tag public">public</span></span> <span class="anchor" id="instance68"><span class="tag instance">68</span></span> Array#<span class="feature-name">sample</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">sample</code></li></ul></div></div><div class="user-item"><div class="p">The elements are chosen by using random and unique indices into the array in order to ensure that an element doesn’t repeat itself unless the array already contained duplicate elements.</div><div class="p">If the array is empty the first form returns <code class="inline">nil</code> and the second form returns an empty array.</div><span class="head">Usage</span> <code class="inline"></code> → Object<div class="p">Chooses a random element from the array. If the array is empty,returns <code class="inline">nil</code>.</div><span class="head">Usage</span> <code class="inline">(n)</code> → Array<div class="p">Chooses <code class="inline">n</code> random elements from the array. If the array is empty, returns an empty array.</div><span class="head">Usage</span> <code class="inline">(random: rng)</code> → Object<span class="head">Usage</span> <code class="inline">(n, random: rng)</code> → Array<div class="p">The optional <code class="inline">rng</code> argument will be used as the random number generator.</div><div class="CodeRay">
953
+ <div class="code"><pre>a = [<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>, <span class="integer">4</span>, <span class="integer">5</span>, <span class="integer">6</span>, <span class="integer">7</span>, <span class="integer">8</span>, <span class="integer">9</span>, <span class="integer">10</span>]
954
+ a.sample <span class="comment">#=&gt; 7</span>
955
+ a.sample(<span class="integer">4</span>) <span class="comment">#=&gt; [6, 4, 2, 5]</span>
956
+ </pre></div>
957
+ </div>
958
+ </div><div class="dev-item"><div class="p indent anchor" id="missing_test18"><span class="hang-indent">​</span><span class="tag missing_test">Missing test</span><span class="dev-text missing_test"> Not unit tested.</span></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature84"><span class="anchor" id="public72"><span class="tag public">public</span></span> <span class="anchor" id="instance69"><span class="tag instance">69</span></span> Array#<span class="feature-name">select</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">select</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">Enumerable#select</code>.</div><span class="head">Usage</span> <code class="inline">{|item| block}</code> → Array<div class="p">Returns a new array containing all elements of ary for which the given block returns a true value.</div><span class="head">Usage</span> <code class="inline"></code> → Enumerator<div class="CodeRay">
959
+ <div class="code"><pre>[<span class="integer">1</span>,<span class="integer">2</span>,<span class="integer">3</span>,<span class="integer">4</span>,<span class="integer">5</span>].select{|num| num.even?} <span class="comment">#=&gt; [2, 4]</span>
960
+
961
+ a = <span class="string"><span class="delimiter">%w{</span><span class="content">a b c d e f</span><span class="delimiter">}</span></span>
962
+ a.select{|v| v =~ <span class="regexp"><span class="delimiter">/</span><span class="content">[aeiou]</span><span class="delimiter">/</span></span>} <span class="comment">#=&gt; [&quot;a&quot;, &quot;e&quot;]</span>
963
+ </pre></div>
964
+ </div>
965
+ </div><div class="dev-item"><div class="p"><span class="head">Test 83.</span> ruby/test/ruby/test_array.rb:test_find_all_0:1/2</div><div class="anchor" id="success476"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">476</span> <code class="inline">[].<span class="bold">select</span><span class="verification">.</span><span class="verification">succeed?</span><span class="verification"></span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature85"><span class="anchor" id="public73"><span class="tag public">public</span></span> <span class="anchor" id="instance70"><span class="tag instance">70</span></span> Array#<span class="feature-name">select!</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">select!</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">#keep_if</code></div><span class="head">Usage</span> <code class="inline">{|item| block}</code> → Array | <code class="inline">nil</code><div class="p">Invokes the given block passing in successive elements from <code class="inline">self</code>, deleting elements for which the block returns a false value.</div><div class="p">If changes were made, it will return <code class="inline">self</code>, otherwise it returns <code class="inline">nil</code>.</div><span class="head">Usage</span> <code class="inline"></code> → Enumerator</div><div class="dev-item"><div class="p indent anchor" id="missing_test19"><span class="hang-indent">​</span><span class="tag missing_test">Missing test</span><span class="dev-text missing_test"> Not unit tested.</span></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature86"><span class="anchor" id="public74"><span class="tag public">public</span></span> <span class="anchor" id="instance71"><span class="tag instance">71</span></span> Array#<span class="feature-name">shift</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">shift</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">#unshift</code> for the opposite effect.</div><span class="head">Usage</span> <code class="inline"></code> → Object | <code class="inline">nil</code><div class="p">Removes the first element of <code class="inline">self</code> and returns it (shifting all other elements down by one). Returns <code class="inline">nil</code> if the array is empty.</div><span class="head">Usage</span> <code class="inline">(n)</code> → Array<div class="p">Returns an array of the first <code class="inline">n</code> elements (or less) just like <code class="inline">array.slice!(0, n)</code> does. With <code class="inline">ary</code> containing only the remainder elements, not including what was shifted to <code class="inline">new_ary</code>.</div><div class="CodeRay">
966
+ <div class="code"><pre>args = [<span class="string"><span class="delimiter">&quot;</span><span class="content">-m</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">-q</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">filename</span><span class="delimiter">&quot;</span></span>]
967
+ args.shift <span class="comment">#=&gt; &quot;-m&quot;</span>
968
+ args <span class="comment">#=&gt; [&quot;-q&quot;, &quot;filename&quot;]</span>
969
+
970
+ args = [<span class="string"><span class="delimiter">&quot;</span><span class="content">-m</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">-q</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">filename</span><span class="delimiter">&quot;</span></span>]
971
+ args.shift(<span class="integer">2</span>) <span class="comment">#=&gt; [&quot;-m&quot;, &quot;-q&quot;]</span>
972
+ args <span class="comment">#=&gt; [&quot;filename&quot;]</span>
973
+ </pre></div>
974
+ </div>
975
+ </div><div class="dev-item"><div class="p"><span class="head">Test 84.</span> ruby/test/ruby/test_array.rb:test_unshift_error</div><div class="anchor" id="bug33"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">33</span> <code class="inline">[].<span class="bold">shift</span>(&quot;cat&quot;)<span class="verification">.</span><span class="verification">raise?</span><span class="verification">(RuntimeError)</span></code></div><ul><li><code class="inline">shift</code>: <span class="dev-text bug">TypeError. No implicit conversion of String into Integer.</span></li></ul></div><div class="anchor" id="bug34"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">34</span> <code class="inline">[].<span class="bold">shift</span><span class="verification">.</span><span class="verification">raise?</span><span class="verification">(RuntimeError)</span></code></div><ul><li><code class="inline">shift</code>: <span class="dev-text bug">Did not raise an exception.</span></li></ul></div><div class="p"><span class="head">Test 85.</span> ruby/test/ruby/test_array.rb:test_beg_end_0:3/6</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
976
+ <div class="code"><pre>x = [<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>, <span class="integer">4</span>, <span class="integer">5</span>]</pre></div>
977
+ </div>
978
+ <div class="anchor" id="success477"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">477</span> <code class="inline">x.<span class="bold">shift</span> <span class="verification">==</span><span class="verification"> 1</span></code></div></div><div class="anchor" id="bug35"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">35</span> <code class="inline">x.<span class="bold">shift</span>(3) <span class="verification">==</span><span class="verification"> [2, 3, 4]</span></code></div><ul><li><code class="inline">shift</code>: <span class="dev-text bug">The receiver of verification <code class="inline">==</code> is <code class="inline">[1, 2, 3]</code>.</span></li></ul></div><div class="anchor" id="bug36"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">36</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [5]</span></code></div><ul><li><code class="inline">shift</code>: <span class="dev-text bug">The receiver of verification <code class="inline">==</code> is <code class="inline">[4, 5]</code>.</span></li></ul></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature87"><span class="anchor" id="public75"><span class="tag public">public</span></span> <span class="anchor" id="instance72"><span class="tag instance">72</span></span> Array#<span class="feature-name">shuffle</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">shuffle</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline"></code> → Array<div class="p">Returns a new array with elements of <code class="inline">self</code> shuffled.</div><div class="CodeRay">
979
+ <div class="code"><pre>a = [<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>] <span class="comment">#=&gt; [1, 2, 3]</span>
980
+ a.shuffle <span class="comment">#=&gt; [2, 3, 1]</span>
981
+ </pre></div>
982
+ </div>
983
+ <span class="head">Usage</span> <code class="inline">(random: rng)</code> → Array<div class="p">The optional <code class="inline">rng</code> argument will be used as the random number generator.</div><div class="CodeRay">
984
+ <div class="code"><pre>a.shuffle(<span class="key">random</span>: <span class="constant">Random</span>.new(<span class="integer">1</span>)) <span class="comment">#=&gt; [1, 3, 2]</span>
985
+ </pre></div>
986
+ </div>
987
+ </div><div class="dev-item"><div class="p indent anchor" id="missing_test20"><span class="hang-indent">​</span><span class="tag missing_test">Missing test</span><span class="dev-text missing_test"> Not unit tested.</span></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature88"><span class="anchor" id="public76"><span class="tag public">public</span></span> <span class="anchor" id="instance73"><span class="tag instance">73</span></span> Array#<span class="feature-name">shuffle!</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">shuffle!</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline"></code> → Array<div class="p">Shuffles elements in <code class="inline">self</code> in place.</div><span class="head">Usage</span> <code class="inline">(random: rng)</code> → Array<div class="p">The optional <code class="inline">rng</code> argument will be used as the random number generator.</div></div><div class="dev-item"><div class="p indent anchor" id="missing_test21"><span class="hang-indent">​</span><span class="tag missing_test">Missing test</span><span class="dev-text missing_test"> Not unit tested.</span></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature89"><span class="anchor" id="public77"><span class="tag public">public</span></span> <span class="anchor" id="instance74"><span class="tag instance">74</span></span> Array#<span class="feature-name">size</span> <span class="anchor" id="misplaced3"><span class="tag misplaced">Misplaced</span><span class="dev-text misplaced">  Defined as alias of <code class="inline">length</code>.</span></span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">size</code></li></ul></div></div><div class="user-item"><div class="p">Alias for: <code class="inline">length</code></div></div><div class="dev-item"><div class="p"><span class="head">Test 86.</span> ruby/test/ruby/test_array.rb:test_size</div><div class="anchor" id="success478"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">478</span> <code class="inline">[].<span class="bold">size</span><span class="verification">.</span><span class="verification">zero?</span><span class="verification"></span></code></div></div><div class="anchor" id="success479"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">479</span> <code class="inline">[1].<span class="bold">size</span> <span class="verification">==</span><span class="verification"> 1</span></code></div></div><div class="anchor" id="success480"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">480</span> <code class="inline">Array[*(0..99).to_a].<span class="bold">size</span> <span class="verification">==</span><span class="verification"> 100</span></code></div></div><div class="p indent anchor" id="missing_doc2"><span class="hang-indent">​</span><span class="tag missing_doc">Missing Doc</span><span class="dev-text missing_doc"> No method signature given.</span></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature90"><span class="anchor" id="public78"><span class="tag public">public</span></span> <span class="anchor" id="instance75"><span class="tag instance">75</span></span> Array#<span class="feature-name">slice</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">slice</code></li></ul></div></div><div class="user-item"><div class="p">Element Reference</div><div class="p">Negative indices count backward from the end of the array (<code class="inline">-1</code> is the last element).</div><div class="p">Returns <code class="inline">nil</code> if the index (or starting index) are out of range.</div><span class="head">Usage</span> <code class="inline">(index)</code> → Object | <code class="inline">nil</code><div class="p">Returns the element at <code class="inline">index</code>.</div><span class="head">Usage</span> <code class="inline">(start, length)</code> → Array | <code class="inline">nil</code><span class="head">Usage</span> <code class="inline">(range)</code> → Array | <code class="inline">nil</code><div class="p">Returns a subarray starting at the <code class="inline">start</code> index and continuing for <code class="inline">length</code> elements, or a subarray specified by <code class="inline">range</code> of indices.</div><div class="p">The starting index is just before an element.</div><div class="p">An empty array is returned when the starting index for an element range is at the end of the array.</div><div class="CodeRay">
988
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">d</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">e</span><span class="delimiter">&quot;</span></span>]
989
+ a[<span class="integer">2</span>] + a[<span class="integer">0</span>] + a[<span class="integer">1</span>] <span class="comment">#=&gt; &quot;cab&quot;</span>
990
+ a[<span class="integer">6</span>] <span class="comment">#=&gt; nil</span>
991
+ a[<span class="integer">1</span>, <span class="integer">2</span>] <span class="comment">#=&gt; [&quot;b&quot;, &quot;c&quot;]</span>
992
+ a[<span class="integer">1</span>..<span class="integer">3</span>] <span class="comment">#=&gt; [&quot;b&quot;, &quot;c&quot;, &quot;d&quot;]</span>
993
+ a[<span class="integer">4</span>..<span class="integer">7</span>] <span class="comment">#=&gt; [&quot;e&quot;]</span>
994
+ a[<span class="integer">6</span>..<span class="integer">10</span>] <span class="comment">#=&gt; nil</span>
995
+ a[<span class="integer">-3</span>, <span class="integer">3</span>] <span class="comment">#=&gt; [&quot;c&quot;, &quot;d&quot;, &quot;e&quot;]</span>
996
+ <span class="comment"># special cases</span>
997
+ a[<span class="integer">5</span>] <span class="comment">#=&gt; nil</span>
998
+ a[<span class="integer">6</span>, <span class="integer">1</span>] <span class="comment">#=&gt; nil</span>
999
+ a[<span class="integer">5</span>, <span class="integer">1</span>] <span class="comment">#=&gt; []</span>
1000
+ a[<span class="integer">5</span>..<span class="integer">10</span>] <span class="comment">#=&gt; []</span>
1001
+ </pre></div>
1002
+ </div>
1003
+ </div><div class="dev-item"><div class="p indent anchor" id="missing_test22"><span class="hang-indent">​</span><span class="tag missing_test">Missing test</span><span class="dev-text missing_test"> Not unit tested.</span></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature91"><span class="anchor" id="public79"><span class="tag public">public</span></span> <span class="anchor" id="instance76"><span class="tag instance">76</span></span> Array#<span class="feature-name">slice!</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">slice!</code></li></ul></div></div><div class="user-item"><div class="p">Returns the deleted object (or objects), or <code class="inline">nil</code> if the index is out of range.</div><span class="head">Usage</span> <code class="inline">(index)</code> → Object | <code class="inline">nil</code><div class="p">Deletes the element given by an index.</div><span class="head">Usage</span> <code class="inline">(start, length)</code> → Array | <code class="inline">nil</code><span class="head">Usage</span> <code class="inline">(range)</code> → Array | <code class="inline">nil</code><div class="p">Deletes the element(s) given by an index up to <code class="inline">length</code> elements or by <code class="inline">range</code>.</div><div class="CodeRay">
1004
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>]
1005
+ a.slice!(<span class="integer">1</span>) <span class="comment">#=&gt; &quot;b&quot;</span>
1006
+ a <span class="comment">#=&gt; [&quot;a&quot;, &quot;c&quot;]</span>
1007
+ a.slice!(<span class="integer">-1</span>) <span class="comment">#=&gt; &quot;c&quot;</span>
1008
+ a <span class="comment">#=&gt; [&quot;a&quot;]</span>
1009
+ a.slice!(<span class="integer">100</span>) <span class="comment">#=&gt; nil</span>
1010
+ a <span class="comment">#=&gt; [&quot;a&quot;]</span>
1011
+ </pre></div>
1012
+ </div>
1013
+ </div><div class="dev-item"><div class="p"><span class="head">Test 87.</span> ruby/test/ruby/test_array.rb:test_slice!</div><div class="anchor" id="success481"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">481</span> <code class="inline">[1, 2, 3, 4, 5].<span class="bold">slice!</span>(2) <span class="verification">==</span><span class="verification"> 3</span></code></div></div><div class="anchor" id="success482"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">482</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2, 4, 5]</span></code></div></div><div class="anchor" id="success483"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">483</span> <code class="inline">[1, 2, 3, 4, 5].<span class="bold">slice!</span>(-2) <span class="verification">==</span><span class="verification"> 4</span></code></div></div><div class="anchor" id="success484"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">484</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2, 3, 5]</span></code></div></div><div class="anchor" id="success485"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">485</span> <code class="inline">[1, 2, 3, 4, 5].<span class="bold">slice!</span>(2, 2) <span class="verification">==</span><span class="verification"> [3, 4]</span></code></div></div><div class="anchor" id="success486"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">486</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2, 5]</span></code></div></div><div class="anchor" id="success487"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">487</span> <code class="inline">[1, 2, 3, 4, 5].<span class="bold">slice!</span>(-2, 2) <span class="verification">==</span><span class="verification"> [4, 5]</span></code></div></div><div class="anchor" id="success488"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">488</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2, 3]</span></code></div></div><div class="anchor" id="success489"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">489</span> <code class="inline">[1, 2, 3, 4, 5].<span class="bold">slice!</span>(2..3) <span class="verification">==</span><span class="verification"> [3, 4]</span></code></div></div><div class="anchor" id="success490"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">490</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2, 5]</span></code></div></div><div class="anchor" id="success491"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">491</span> <code class="inline">[1, 2, 3, 4, 5].<span class="bold">slice!</span>(20)<span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="anchor" id="success492"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">492</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2, 3, 4, 5]</span></code></div></div><div class="anchor" id="success493"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">493</span> <code class="inline">[1, 2, 3, 4, 5].<span class="bold">slice!</span>(-6)<span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="anchor" id="success494"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">494</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2, 3, 4, 5]</span></code></div></div><div class="anchor" id="success495"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">495</span> <code class="inline">[1, 2, 3, 4, 5].<span class="bold">slice!</span>(-6..4)<span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="anchor" id="success496"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">496</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2, 3, 4, 5]</span></code></div></div><div class="anchor" id="success497"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">497</span> <code class="inline">[1, 2, 3, 4, 5].<span class="bold">slice!</span>(-6, 2)<span class="verification">.</span><span class="verification">nil?</span><span class="verification"></span></code></div></div><div class="anchor" id="success498"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">498</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2, 3, 4, 5]</span></code></div></div><div class="anchor" id="success499"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">499</span> <code class="inline">[1].<span class="bold">slice!</span><span class="verification">.</span><span class="verification">raise?</span><span class="verification">(ArgumentError)</span></code></div></div><div class="anchor" id="success500"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">500</span> <code class="inline">[1].<span class="bold">slice!</span>(0, 0, 0)<span class="verification">.</span><span class="verification">raise?</span><span class="verification">(ArgumentError)</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature92"><span class="anchor" id="public80"><span class="tag public">public</span></span> <span class="anchor" id="instance77"><span class="tag instance">77</span></span> Array#<span class="feature-name">sort</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">sort</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">Enumerable#sort_by</code>.</div><div class="p">Returns a new array created by sorting <code class="inline">self</code>.</div><span class="head">Usage</span> <code class="inline"></code> → Array<div class="p">Comparisons for the <code class="inline">sort</code> will be done using the <code class="inline">&lt;=&gt;</code> operator.</div><span class="head">Usage</span> <code class="inline">{|a, b| block}</code> → Array<div class="p">Comparisons for the <code class="inline">sort</code> will be done using the code block.</div><div class="p">The block must implement a comparison between <code class="inline">a</code> and <code class="inline">b</code>, and return <code class="inline">-1</code>, when <code class="inline">a</code> follows <code class="inline">b</code>, <code class="inline">0</code> when <code class="inline">a</code> and <code class="inline">b</code> are equivalent, or <code class="inline">+1</code> if <code class="inline">b</code> follows <code class="inline">a</code>.</div><div class="CodeRay">
1014
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">d</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">e</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>]
1015
+ a.sort <span class="comment">#=&gt; [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;e&quot;]</span>
1016
+ a.sort{|x,y| y &lt;=&gt; x} <span class="comment">#=&gt; [&quot;e&quot;, &quot;d&quot;, &quot;c&quot;, &quot;b&quot;, &quot;a&quot;]</span>
1017
+ </pre></div>
1018
+ </div>
1019
+ </div><div class="dev-item"><div class="p"><span class="head">Test 88.</span> ruby/test/ruby/test_array.rb:test_sort_0:1/2</div><div class="anchor" id="success501"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">501</span> <code class="inline">[&quot;it&quot;, &quot;came&quot;, &quot;to&quot;, &quot;pass&quot;, &quot;that&quot;, &quot;...&quot;].<span class="bold">sort</span><span class="verification">.</span><span class="verification">join</span><span class="verification">(&quot; &quot;)</span> <span class="verification">==</span><span class="verification"> &quot;... came it pass that to&quot;</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature93"><span class="anchor" id="public81"><span class="tag public">public</span></span> <span class="anchor" id="instance78"><span class="tag instance">78</span></span> Array#<span class="feature-name">sort!</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">sort!</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">Enumerable#sort_by</code>.</div><div class="p">Sorts <code class="inline">self</code> in place.</div><span class="head">Usage</span> <code class="inline"></code> → Array<div class="p">Comparisons for the <code class="inline">sort</code> will be done using the <code class="inline">&lt;=&gt;</code> operator.</div><span class="head">Usage</span> <code class="inline">{|a, b| block}</code> → Array<div class="p">Comparisons for the <code class="inline">sort</code> will be done using the code block.</div><div class="p">The block must implement a comparison between <code class="inline">a</code> and <code class="inline">b</code>, and return <code class="inline">-1</code>, when <code class="inline">a</code> follows <code class="inline">b</code>, <code class="inline">0</code> when <code class="inline">a</code> and <code class="inline">b</code> are equivalent, or <code class="inline">+1</code> if <code class="inline">b</code> follows <code class="inline">a</code>.</div><div class="CodeRay">
1020
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">d</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">e</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>]
1021
+ a.sort! <span class="comment">#=&gt; [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;e&quot;]</span>
1022
+ a.sort!{|x,y| y &lt;=&gt; x} <span class="comment">#=&gt; [&quot;e&quot;, &quot;d&quot;, &quot;c&quot;, &quot;b&quot;, &quot;a&quot;]</span>
1023
+ </pre></div>
1024
+ </div>
1025
+ </div><div class="dev-item"><div class="p"><span class="head">Test 89.</span> ruby/test/ruby/test_array.rb:test_sort_0:2/2</div><div class="p"><span class="head">Test 89.1.</span> sort with condition</div><div class="anchor" id="success502"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">502</span> <code class="inline">[2, 5, 3, 1, 7].<span class="bold">sort!</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:2159)}<span class="verification">.</span><span class="verification">succeed?</span><span class="verification"></span></code></div></div><div class="anchor" id="success503"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">503</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2, 3, 5, 7]</span></code></div></div><div class="p"><span class="head">Test 89.2.</span> reverse sort</div><div class="anchor" id="success504"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">504</span> <code class="inline">[2, 5, 3, 1, 7].<span class="bold">sort!</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:2162)}<span class="verification">.</span><span class="verification">succeed?</span><span class="verification"></span></code></div></div><div class="anchor" id="success505"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">505</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [7, 5, 3, 2, 1]</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature94"><span class="anchor" id="public82"><span class="tag public">public</span></span> <span class="anchor" id="instance79"><span class="tag instance">79</span></span> Array#<span class="feature-name">sort_by!</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">sort_by!</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline">{|obj| block}</code> → Array<div class="p">Sorts <code class="inline">self</code> in place using a set of keys generated by mapping the values in self through the given block.</div><span class="head">Usage</span> <code class="inline"></code> → Enumerator</div><div class="dev-item"><div class="p"><span class="head">Test 90.</span> ruby/test/ruby/test_array.rb:test_sort_by!</div><div class="anchor" id="success506"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">506</span> <code class="inline">[1, 3, 5, 2, 4].<span class="bold">sort_by!</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:2170)}<span class="verification">.</span><span class="verification">succeed?</span><span class="verification"></span></code></div></div><div class="anchor" id="success507"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">507</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [5, 4, 3, 2, 1]</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature95"><span class="anchor" id="public83"><span class="tag public">public</span></span> <span class="anchor" id="instance80"><span class="tag instance">80</span></span> Array#<span class="feature-name">take</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">take</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">#drop</code></div><span class="head">Usage</span> <code class="inline">(n)</code> → Array<div class="p">Returns first <code class="inline">n</code> elements from the array.</div><div class="p">If a negative number is given, raises an <code class="inline">ArgumentError</code>.</div><div class="CodeRay">
1026
+ <div class="code"><pre>a = [<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>, <span class="integer">4</span>, <span class="integer">5</span>, <span class="integer">0</span>]
1027
+ a.take(<span class="integer">3</span>) <span class="comment">#=&gt; [1, 2, 3]</span>
1028
+ </pre></div>
1029
+ </div>
1030
+ </div><div class="dev-item"><div class="p"><span class="head">Test 91.</span> ruby/test/ruby/test_array.rb:test_take</div><div class="anchor" id="success508"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">508</span> <code class="inline">[1, 2, 3, 4, 5, 0].<span class="bold">take</span>(3) <span class="verification">==</span><span class="verification"> [1, 2, 3]</span></code></div></div><div class="p"><span class="head">Test 91.1.</span> ruby-dev:34123</div><div class="anchor" id="success509"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">509</span> <code class="inline">[1, 2].<span class="bold">take</span>(-1)<span class="verification">.</span><span class="verification">raise?</span><span class="verification">(ArgumentError)</span></code></div></div><div class="p"><span class="head">Test 91.2.</span> ruby-dev:34123</div><div class="anchor" id="success510"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">510</span> <code class="inline">[1, 2].<span class="bold">take</span>(1000000000) <span class="verification">==</span><span class="verification"> [1, 2]</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature96"><span class="anchor" id="public84"><span class="tag public">public</span></span> <span class="anchor" id="instance81"><span class="tag instance">81</span></span> Array#<span class="feature-name">take_while</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">take_while</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">#drop_while</code></div><span class="head">Usage</span> <code class="inline">{|arr| block}</code> → Array<div class="p">Passes elements to the block until the block returns <code class="inline">nil</code> or <code class="inline">false</code>, then stops iterating and returns an array of all prior elements.</div><span class="head">Usage</span> <code class="inline"></code> → Enumerator<div class="CodeRay">
1031
+ <div class="code"><pre>a = [<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>, <span class="integer">4</span>, <span class="integer">5</span>, <span class="integer">0</span>]
1032
+ a.take_while{|i| i &lt; <span class="integer">3</span>} <span class="comment">#=&gt; [1, 2]</span>
1033
+ </pre></div>
1034
+ </div>
1035
+ </div><div class="dev-item"><div class="p"><span class="head">Test 92.</span> ruby/test/ruby/test_array.rb:test_take_while</div><div class="anchor" id="success511"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">511</span> <code class="inline">[1, 2, 3, 4, 5, 0].<span class="bold">take_while</span>{(/home/sawa/Dropbox/implicit/gem/manager/examples/array/spec:2199)} <span class="verification">==</span><span class="verification"> [1, 2]</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature97"><span class="anchor" id="public85"><span class="tag public">public</span></span> <span class="anchor" id="instance82"><span class="tag instance">82</span></span> Array#<span class="feature-name">to_a</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">to_a</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline"></code> → Array<div class="p">Returns <code class="inline">self</code>.</div><div class="p">If called on a subclass of <code class="inline">Array</code>, converts the receiver to an <code class="inline">Array</code> object.</div></div><div class="dev-item"><div class="p indent anchor" id="missing_test23"><span class="hang-indent">​</span><span class="tag missing_test">Missing test</span><span class="dev-text missing_test"> Not unit tested.</span></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature98"><span class="anchor" id="public86"><span class="tag public">public</span></span> <span class="anchor" id="instance83"><span class="tag instance">83</span></span> Array#<span class="feature-name">to_ary</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">to_ary</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline"></code> → Array<div class="p">Returns <code class="inline">self</code>.</div></div><div class="dev-item"><div class="p indent anchor" id="missing_test24"><span class="hang-indent">​</span><span class="tag missing_test">Missing test</span><span class="dev-text missing_test"> Not unit tested.</span></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature99"><span class="anchor" id="public87"><span class="tag public">public</span></span> <span class="anchor" id="instance84"><span class="tag instance">84</span></span> Array#<span class="feature-name">to_h</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">to_h</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline"></code> → Hash<div class="p">Returns the result of interpreting <code class="inline">ary</code> as an array of <code class="inline">[key, value]</code> pairs.</div><div class="CodeRay">
1036
+ <div class="code"><pre>[[<span class="symbol">:foo</span>, <span class="symbol">:bar</span>], [<span class="integer">1</span>, <span class="integer">2</span>]].to_h
1037
+ <span class="comment"># =&gt; {:foo =&gt; :bar, 1 =&gt; 2}</span>
1038
+ </pre></div>
1039
+ </div>
1040
+ </div><div class="dev-item"><div class="p indent anchor" id="missing_test25"><span class="hang-indent">​</span><span class="tag missing_test">Missing test</span><span class="dev-text missing_test"> Not unit tested.</span></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature100"><span class="anchor" id="public88"><span class="tag public">public</span></span> <span class="anchor" id="instance85"><span class="tag instance">85</span></span> Array#<span class="feature-name">to_s</span> <span class="anchor" id="misplaced4"><span class="tag misplaced">Misplaced</span><span class="dev-text misplaced">  Defined as alias of <code class="inline">inspect</code>.</span></span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">to_s</code></li></ul></div></div><div class="user-item"><div class="p">Alias for: <code class="inline">inspect</code>.</div></div><div class="dev-item"><div class="p"><span class="head">Test 93.</span> ruby/test/ruby/test_array.rb:test_to_s</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
1041
+ <div class="code"><pre><span class="global-variable">$,</span> = <span class="string"><span class="delimiter">&quot;</span><span class="delimiter">&quot;</span></span></pre></div>
1042
+ </div>
1043
+ <div class="anchor" id="success512"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">512</span> <code class="inline">[].<span class="bold">to_s</span> <span class="verification">==</span><span class="verification"> &quot;[]&quot;</span></code></div></div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
1044
+ <div class="code"><pre><span class="global-variable">$,</span> = <span class="string"><span class="delimiter">&quot;</span><span class="delimiter">&quot;</span></span></pre></div>
1045
+ </div>
1046
+ <div class="anchor" id="success513"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">513</span> <code class="inline">[1, 2].<span class="bold">to_s</span> <span class="verification">==</span><span class="verification"> &quot;[1, 2]&quot;</span></code></div></div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
1047
+ <div class="code"><pre><span class="global-variable">$,</span> = <span class="string"><span class="delimiter">&quot;</span><span class="delimiter">&quot;</span></span></pre></div>
1048
+ </div>
1049
+ <div class="anchor" id="success514"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">514</span> <code class="inline">[1, 2, 3].<span class="bold">to_s</span> <span class="verification">==</span><span class="verification"> &quot;[1, 2, 3]&quot;</span></code></div></div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
1050
+ <div class="code"><pre><span class="global-variable">$,</span> = <span class="string"><span class="delimiter">&quot;</span><span class="content">:</span><span class="delimiter">&quot;</span></span></pre></div>
1051
+ </div>
1052
+ <div class="anchor" id="success515"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">515</span> <code class="inline">[1, 2, 3].<span class="bold">to_s</span> <span class="verification">==</span><span class="verification"> &quot;[1, 2, 3]&quot;</span></code></div></div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
1053
+ <div class="code"><pre><span class="global-variable">$,</span> = <span class="predefined-constant">nil</span></pre></div>
1054
+ </div>
1055
+ <div class="p"><span class="head">Teardown</span></div><div class="p indent anchor" id="missing_doc3"><span class="hang-indent">​</span><span class="tag missing_doc">Missing Doc</span><span class="dev-text missing_doc"> No method signature given.</span></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature101"><span class="anchor" id="public89"><span class="tag public">public</span></span> <span class="anchor" id="instance86"><span class="tag instance">86</span></span> Array#<span class="feature-name">transpose</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">transpose</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline"></code> → Array<div class="p">Assumes that <code class="inline">self</code> is an array of arrays and transposes the rows and columns.</div><div class="CodeRay">
1056
+ <div class="code"><pre>a = [[<span class="integer">1</span>,<span class="integer">2</span>], [<span class="integer">3</span>,<span class="integer">4</span>], [<span class="integer">5</span>,<span class="integer">6</span>]]
1057
+ a.transpose <span class="comment">#=&gt; [[1, 3, 5], [2, 4, 6]]</span>
1058
+ </pre></div>
1059
+ </div>
1060
+ <div class="p">If the length of the subarrays don’t match, an <code class="inline">IndexError</code> is raised.</div></div><div class="dev-item"><div class="p"><span class="head">Test 94.</span> ruby/test/ruby/test_array.rb:test_transpose</div><div class="anchor" id="success516"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">516</span> <code class="inline">[[1, 2, 3], [:a, :b, :c]].<span class="bold">transpose</span> <span class="verification">==</span><span class="verification"> [[1, :a], [2, :b], [3, :c]]</span></code></div></div><div class="anchor" id="success517"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">517</span> <code class="inline">[[1, 2, 3], [:a, :b]].<span class="bold">transpose</span><span class="verification">.</span><span class="verification">raise?</span><span class="verification">(IndexError)</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature102"><span class="anchor" id="public90"><span class="tag public">public</span></span> <span class="anchor" id="instance87"><span class="tag instance">87</span></span> Array#<span class="feature-name">uniq</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">uniq</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline"></code> → Array<div class="p">Returns a new array by removing duplicate values in <code class="inline">self</code>.</div><div class="p">It compares values using their hash and eql? methods for efficiency.</div><span class="head">Usage</span> <code class="inline">{|item| ...}</code> → Array<div class="p">It will use the return value of the block for comparison.</div><div class="CodeRay">
1061
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>]
1062
+ a.uniq <span class="comment"># =&gt; [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;]</span>
1063
+
1064
+ b = [[<span class="string"><span class="delimiter">&quot;</span><span class="content">student</span><span class="delimiter">&quot;</span></span>,<span class="string"><span class="delimiter">&quot;</span><span class="content">sam</span><span class="delimiter">&quot;</span></span>], [<span class="string"><span class="delimiter">&quot;</span><span class="content">student</span><span class="delimiter">&quot;</span></span>,<span class="string"><span class="delimiter">&quot;</span><span class="content">george</span><span class="delimiter">&quot;</span></span>], [<span class="string"><span class="delimiter">&quot;</span><span class="content">teacher</span><span class="delimiter">&quot;</span></span>,<span class="string"><span class="delimiter">&quot;</span><span class="content">matz</span><span class="delimiter">&quot;</span></span>]]
1065
+ b.uniq{|s| s.first} <span class="comment"># =&gt; [[&quot;student&quot;, &quot;sam&quot;], [&quot;teacher&quot;, &quot;matz&quot;]]</span>
1066
+ </pre></div>
1067
+ </div>
1068
+ </div><div class="dev-item"><div class="p indent anchor" id="missing_test26"><span class="hang-indent">​</span><span class="tag missing_test">Missing test</span><span class="dev-text missing_test"> Not unit tested.</span></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature103"><span class="anchor" id="public91"><span class="tag public">public</span></span> <span class="anchor" id="instance88"><span class="tag instance">88</span></span> Array#<span class="feature-name">uniq!</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">uniq!</code></li></ul></div></div><div class="user-item"><span class="head">Usage</span> <code class="inline"></code> → Array | <code class="inline">nil</code><div class="p">Removes duplicate elements from <code class="inline">self</code>.</div><div class="p">It compares values using their <code class="inline">hash</code> and <code class="inline">eql?</code> methods for efficiency.</div><div class="p">Returns <code class="inline">nil</code> if no changes are made (that is, no duplicates are found).</div><span class="head">Usage</span> <code class="inline">{|item| ...}</code> → Array | <code class="inline">nil</code><div class="p">It will use the return value of the block for comparison.</div><div class="CodeRay">
1069
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>]
1070
+ a.uniq! <span class="comment"># =&gt; [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;]</span>
1071
+
1072
+ b = [<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>]
1073
+ b.uniq! <span class="comment"># =&gt; nil</span>
1074
+
1075
+ c = [[<span class="string"><span class="delimiter">&quot;</span><span class="content">student</span><span class="delimiter">&quot;</span></span>,<span class="string"><span class="delimiter">&quot;</span><span class="content">sam</span><span class="delimiter">&quot;</span></span>], [<span class="string"><span class="delimiter">&quot;</span><span class="content">student</span><span class="delimiter">&quot;</span></span>,<span class="string"><span class="delimiter">&quot;</span><span class="content">george</span><span class="delimiter">&quot;</span></span>], [<span class="string"><span class="delimiter">&quot;</span><span class="content">teacher</span><span class="delimiter">&quot;</span></span>,<span class="string"><span class="delimiter">&quot;</span><span class="content">matz</span><span class="delimiter">&quot;</span></span>]]
1076
+ c.uniq!{|s| s.first} <span class="comment"># =&gt; [[&quot;student&quot;, &quot;sam&quot;], [&quot;teacher&quot;, &quot;matz&quot;]]</span>
1077
+ </pre></div>
1078
+ </div>
1079
+ </div><div class="dev-item"><div class="p"><span class="head">Test 95.</span> ruby/test/ruby/test_array.rb:test_uniq_0</div><div class="anchor" id="success518"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">518</span> <code class="inline">[1, 1, 4, 2, 5, 4, 5, 1, 2].<span class="bold">uniq!</span><span class="verification">.</span><span class="verification">succeed?</span><span class="verification"></span></code></div></div><div class="anchor" id="success519"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">519</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 4, 2, 5]</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature104"><span class="anchor" id="public92"><span class="tag public">public</span></span> <span class="anchor" id="instance89"><span class="tag instance">89</span></span> Array#<span class="feature-name">unshift</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">unshift</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">#shift</code> for the opposite effect.</div><span class="head">Usage</span> <code class="inline">(obj, ...)</code> → Array<div class="p">Prepends objects to the front of <code class="inline">self</code>, moving other elements upwards.</div><div class="CodeRay">
1080
+ <div class="code"><pre>a = [<span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">d</span><span class="delimiter">&quot;</span></span>]
1081
+ a.unshift(<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>) <span class="comment">#=&gt; [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;]</span>
1082
+ a.unshift(<span class="integer">1</span>, <span class="integer">2</span>) <span class="comment">#=&gt; [1, 2, &quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;]</span>
1083
+ </pre></div>
1084
+ </div>
1085
+ </div><div class="dev-item"><div class="p"><span class="head">Test 96.</span> ruby/test/ruby/test_array.rb:test_beg_end_0:4/6</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
1086
+ <div class="code"><pre>x = [<span class="integer">5</span>]</pre></div>
1087
+ </div>
1088
+ <div class="anchor" id="success520"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">520</span> <code class="inline">x.<span class="bold">unshift</span>(2, 3, 4) <span class="verification">==</span><span class="verification"> [2, 3, 4, 5]</span></code></div></div><div class="anchor" id="bug37"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">37</span> <code class="inline">x.<span class="bold">unshift</span>(1) <span class="verification">==</span><span class="verification"> [1, 2, 3, 4, 5]</span></code></div><ul><li><code class="inline">unshift</code>: <span class="dev-text bug">The receiver of verification <code class="inline">==</code> is <code class="inline">[1, 5]</code>.</span></li></ul></div><div class="anchor" id="bug38"><div class="indent dev-text bug p"><span class="hang-indent">​</span><span class="tag bug">38</span> <code class="inline">RECEIVER <span class="verification">==</span><span class="verification"> [1, 2, 3, 4, 5]</span></code></div><ul><li><code class="inline">unshift</code>: <span class="dev-text bug">The receiver of verification <code class="inline">==</code> is <code class="inline">[1, 5]</code>.</span></li></ul></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature105"><span class="anchor" id="public93"><span class="tag public">public</span></span> <span class="anchor" id="instance90"><span class="tag instance">90</span></span> Array#<span class="feature-name">values_at</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">values_at</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">#select</code>.</div><span class="head">Usage</span> <code class="inline">(selector, ...)</code> → Array<div class="p">Returns an array containing the elements in <code class="inline">self</code> corresponding to the given selector(s).</div><div class="p">The selectors may be either integer indices or ranges.</div><div class="CodeRay">
1089
+ <div class="code"><pre>a = <span class="string"><span class="delimiter">%w{</span><span class="content">a b c d e f</span><span class="delimiter">}</span></span>
1090
+ a.values_at(<span class="integer">1</span>, <span class="integer">3</span>, <span class="integer">5</span>) <span class="comment"># =&gt; [&quot;b&quot;, &quot;d&quot;, &quot;f&quot;]</span>
1091
+ a.values_at(<span class="integer">1</span>, <span class="integer">3</span>, <span class="integer">5</span>, <span class="integer">7</span>) <span class="comment"># =&gt; [&quot;b&quot;, &quot;d&quot;, &quot;f&quot;, nil]</span>
1092
+ a.values_at(<span class="integer">-1</span>, <span class="integer">-2</span>, <span class="integer">-2</span>, <span class="integer">-7</span>) <span class="comment"># =&gt; [&quot;f&quot;, &quot;e&quot;, &quot;e&quot;, nil]</span>
1093
+ a.values_at(<span class="integer">4</span>..<span class="integer">6</span>, <span class="integer">3</span>...<span class="integer">6</span>) <span class="comment"># =&gt; [&quot;e&quot;, &quot;f&quot;, nil, &quot;d&quot;, &quot;e&quot;, &quot;f&quot;]</span>
1094
+ </pre></div>
1095
+ </div>
1096
+ </div><div class="dev-item"><div class="p"><span class="head">Test 97.</span> ruby/test/ruby/test_array.rb:test_values_at</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
1097
+ <div class="code"><pre>a = <span class="constant">Array</span>[*(<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>..<span class="string"><span class="delimiter">&quot;</span><span class="content">j</span><span class="delimiter">&quot;</span></span>).to_a]</pre></div>
1098
+ </div>
1099
+ <div class="anchor" id="success521"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">521</span> <code class="inline">a.<span class="bold">values_at</span>(0, 2, 4) <span class="verification">==</span><span class="verification"> [&quot;a&quot;, &quot;c&quot;, &quot;e&quot;]</span></code></div></div><div class="anchor" id="success522"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">522</span> <code class="inline">a.<span class="bold">values_at</span>(-1, -3, -5) <span class="verification">==</span><span class="verification"> [&quot;j&quot;, &quot;h&quot;, &quot;f&quot;]</span></code></div></div><div class="anchor" id="success523"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">523</span> <code class="inline">a.<span class="bold">values_at</span>(-3, 99, 0) <span class="verification">==</span><span class="verification"> [&quot;h&quot;, nil, &quot;a&quot;]</span></code></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature106"><span class="anchor" id="public94"><span class="tag public">public</span></span> <span class="anchor" id="instance91"><span class="tag instance">91</span></span> Array#<span class="feature-name">zip</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">zip</code></li></ul></div></div><div class="user-item"><div class="p">Converts any arguments to arrays, then merges elements of self with corresponding elements from each argument.</div><div class="p">This generates a sequence of <code class="inline">ary.size</code> n-element arrays, where n is one more than the count of arguments.</div><div class="p">If the size of any argument is less than the size of the initial array, <code class="inline">nil</code> values are supplied.</div><span class="head">Usage</span> <code class="inline">(arg, ...)</code> → Array<div class="p">An array of arrays is returned.</div><span class="head">Usage</span> <code class="inline">(arg, ...){|arr| block}</code> → NilClass<div class="p">It is invoked for each output array.</div><div class="CodeRay">
1100
+ <div class="code"><pre>a = [<span class="integer">4</span>, <span class="integer">5</span>, <span class="integer">6</span>]
1101
+ b = [<span class="integer">7</span>, <span class="integer">8</span>, <span class="integer">9</span>]
1102
+ [<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>].zip(a, b) <span class="comment">#=&gt; [[1, 4, 7], [2, 5, 8], [3, 6, 9]]</span>
1103
+ [<span class="integer">1</span>, <span class="integer">2</span>].zip(a, b) <span class="comment">#=&gt; [[1, 4, 7], [2, 5, 8]]</span>
1104
+ a.zip([<span class="integer">1</span>, <span class="integer">2</span>], [<span class="integer">8</span>]) <span class="comment">#=&gt; [[4, 1, 8], [5, 2, nil], [6, nil, nil]]</span>
1105
+ </pre></div>
1106
+ </div>
1107
+ </div><div class="dev-item"><div class="p indent anchor" id="missing_test27"><span class="hang-indent">​</span><span class="tag missing_test">Missing test</span><span class="dev-text missing_test"> Not unit tested.</span></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature107"><span class="anchor" id="public95"><span class="tag public">public</span></span> <span class="anchor" id="instance92"><span class="tag instance">92</span></span> Array#<span class="feature-name">|</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">|</code></li></ul></div></div><div class="user-item"><div class="p">See also <code class="inline">#uniq</code>.</div><span class="head">Usage</span> <code class="inline">other_ary</code> → Array<div class="p">Set Union — Returns a new array by joining <code class="inline">ary</code> with <code class="inline">other_ary</code>, excluding any duplicates and preserving the order from the original array.</div><div class="p">It compares elements using their <code class="inline">hash</code> and <code class="inline">eql?</code> methods for efficiency.</div><div class="CodeRay">
1108
+ <div class="code"><pre>[<span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">b</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>] | [<span class="string"><span class="delimiter">&quot;</span><span class="content">c</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">d</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">a</span><span class="delimiter">&quot;</span></span>] <span class="comment">#=&gt; [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;]</span>
1109
+ </pre></div>
1110
+ </div>
1111
+ </div><div class="dev-item"><div class="p"><span class="head">Test 98.</span> ruby/test/ruby/test_array.rb:ruby/test/ruby/test_array_andor_0:2/2</div><div class="anchor" id="success524"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">524</span> <code class="inline">([1, 2, 3] <span class="bold">|</span> [2, 4, 6]) <span class="verification">==</span><span class="verification"> [1, 2, 3, 4, 6]</span></code></div></div><div class="p"><span class="head">Test 99.</span> ruby/test/ruby/test_array.rb:test_0_literal:5/8</div><div class="anchor" id="success525"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">525</span> <code class="inline">([1, 2, 3] <span class="bold">|</span> [2, 3, 4]) <span class="verification">==</span><span class="verification"> [1, 2, 3, 4]</span></code></div></div></div></div></div></div><div class="module"><div class="feature" onclick="toggleModuleContents(this)"><h1 class="module-header" id="feature108"><span class="anchor" id="public96"><span class="tag public">public</span></span> class <span class="feature-name">String</span></h1><div class="feature-contents"><div class="dev-item"><div class="diagram"><div class="mixins"><div>Comparable</div><div>┊</div><div class="baseline">String</div></div> &lt; <div class="mixins"><div>Kernel</div><div>┊</div><div class="baseline">Object</div></div> &lt; <div class="mixins"><div class="baseline">BasicObject</div></div></div><div class="diagram"><div class="mixins"><div class="baseline">&lt;&lt;String</div></div> &lt; <div class="mixins"><div class="baseline">&lt;&lt;Object</div></div> &lt; <div class="mixins"><div class="baseline">&lt;&lt;BasicObject</div></div> &lt; <div class="mixins"><div class="baseline">Class</div></div> &lt; <div class="mixins"><div class="baseline">Module</div></div> &lt; <div class="mixins"><div>Kernel</div><div>┊</div><div class="baseline">Object</div></div> &lt; <div class="mixins"><div class="baseline">BasicObject</div></div></div></div></div></div><div class="feature" onclick="toggleFeatureContents(this)"><h2 id="feature109"><span class="anchor" id="public97"><span class="tag public">public</span></span> <span class="anchor" id="instance93"><span class="tag instance">93</span></span> String#<span class="feature-name">split</span></h2><div class="feature-contents"><div class="dev-item"><div class="p"><div class="p"><span class="head">Implementation candidates</span></div><ul><li class="implementation"><code class="inline">split</code></li></ul></div><div class="p"><span class="head">Test 100.</span> ruby/test/ruby/test_array.rb:test_split_0</div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
1112
+ <div class="code"><pre>x = <span class="string"><span class="delimiter">&quot;</span><span class="content">The Book of Mormon</span><span class="delimiter">&quot;</span></span>
1113
+ y = x.reverse
1114
+ </pre></div>
1115
+ </div>
1116
+ <div class="anchor" id="success526"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">526</span> <code class="inline">x.<span class="bold">split</span>(//)<span class="verification">.</span><span class="verification">reverse!</span><span class="verification"></span><span class="verification">.</span><span class="verification">join</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> x.reverse</span></code></div></div><div class="anchor" id="success527"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">527</span> <code class="inline">RECEIVER<span class="verification">.</span><span class="verification">reverse!</span><span class="verification"></span> <span class="verification">==</span><span class="verification"> x</span></code></div></div><div class="anchor" id="success528"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">528</span> <code class="inline">&quot;1 byte string&quot;.<span class="bold">split</span>(//)<span class="verification">.</span><span class="verification">reverse</span><span class="verification"></span><span class="verification">.</span><span class="verification">join</span><span class="verification">(&quot;:&quot;)</span> <span class="verification">==</span><span class="verification"> &quot;g:n:i:r:t:s: :e:t:y:b: :1&quot;</span></code></div></div><div class="p"><span class="head">Setup code</span></div><div class="CodeRay">
1117
+ <div class="code"><pre>x = <span class="string"><span class="delimiter">&quot;</span><span class="content">a b c d</span><span class="delimiter">&quot;</span></span></pre></div>
1118
+ </div>
1119
+ <div class="anchor" id="success529"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">529</span> <code class="inline">x.<span class="bold">split</span> <span class="verification">==</span><span class="verification"> [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;]</span></code></div></div><div class="anchor" id="success530"><div class="indent dev-text success p"><span class="hang-indent">​</span><span class="tag success">530</span> <code class="inline">x.<span class="bold">split</span>(&quot; &quot;) <span class="verification">==</span><span class="verification"> [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;]</span></code></div></div><div class="p indent anchor" id="missing_doc4"><span class="hang-indent">​</span><span class="tag missing_doc">Missing Doc</span><span class="dev-text missing_doc"> No paragraph given for user.</span></div></div></div></div></div></div></div><script>//-*-mode: javascript-*-
1120
+
1121
+ // Copyright (c) 2014-2016 sawa
1122
+
1123
+ var main;
1124
+ var scrollMargin;
1125
+
1126
+ // Scroll to the anchor.
1127
+ window.onhashchange = function(e) {
1128
+ // location.href = location.hash;
1129
+ // main.scrollTop -= main.offsetHeight * 0.5 + scrollMargin;
1130
+ main.scrollTop -= scrollMargin;
1131
+ };
1132
+
1133
+ document.body.onload = function() {
1134
+ main = document.getElementById('main');
1135
+ //This line is needed to invoke `window.onhashchange` even when `location.hash`
1136
+ // is the same as the previous load.
1137
+ location.hash = '';
1138
+ //TODO. Import data from webstore.
1139
+ //location.hash =
1140
+ var joinQuery = function(obj, prefix, affix){
1141
+ return prefix + obj.dataset.tags.split(' ').join(affix + ', ' + prefix) + affix;
1142
+ }
1143
+ var tagsumPrefix = '#tagsum-', tagsumAffix = ':not([style="opacity: 0.2;"])';
1144
+ var i, obj, query;
1145
+ query = '.feature:not([style="display: none;"]) .tag.';
1146
+ for(i = 1; obj = document.getElementById('user-feature-navigation' + i); i++) {
1147
+ obj.query = joinQuery(obj, query, '');
1148
+ obj.tagsums = joinQuery(obj, tagsumPrefix, tagsumAffix);
1149
+ initializeNavigation(obj);
1150
+ }
1151
+ for(i = 1; obj = document.getElementById('dev-feature-navigation' + i); i++) {
1152
+ obj.query = joinQuery(obj, query, '');
1153
+ obj.tagsums = joinQuery(obj, tagsumPrefix, tagsumAffix);
1154
+ initializeNavigation(obj);
1155
+ }
1156
+ query = '\
1157
+ .feature:not([style="display: none;"]):not([folded="true"]) \
1158
+ .feature-contents > :not([style="display: none;"]) \
1159
+ .anchor:not([style="display: none;"]) \
1160
+ .tag.';
1161
+ for(i = 1; obj = document.getElementById('anchor-navigation' + i); i++) {
1162
+ obj.query = joinQuery(obj, query, '');
1163
+ obj.tagsums = joinQuery(obj, tagsumPrefix, tagsumAffix);
1164
+ initializeNavigation(obj);
1165
+ }
1166
+ var objs = document.getElementsByClassName('feature');
1167
+ for(var i = 0; i < objs.length; i++) {
1168
+ // TODO. copy from webstore if any.
1169
+ objs[i].hiddenFor = {};
1170
+ // hide(objs[i], Object.keys(objs[i].hiddenFor).length);
1171
+ }
1172
+ switch(document.body.id){
1173
+ case 'user':
1174
+ scrollMargin = 200;
1175
+ // Click "Features" button.
1176
+ document.getElementById('top').children[0].children[1].onclick();
1177
+ break;
1178
+ case 'dev':
1179
+ // Approximates half of line height from experience. TODO: Do it logically.
1180
+ scrollMargin = 200;
1181
+ // Click "Full" button. (Neccessary to do this also for adding `folded` attribute)
1182
+ document.getElementById('top').children[0].children[2].onclick();
1183
+ break;
1184
+ }
1185
+ // Prevents feature toggling.
1186
+ // Overwriting `onclick` does not interfere with linking to `href`; it is different from `onclick`.
1187
+ var objs = document.getElementsByTagName('a');
1188
+ for(var i = 0; i < objs.length; i++) objs[i].onclick = function(e) {e.stopPropagation();};
1189
+ };
1190
+
1191
+ initializeNavigation = function(obj) {
1192
+ obj.features = document.querySelectorAll(obj.query);
1193
+ var sum = obj.features.length;
1194
+ obj.querySelector('.sum').innerText = sum;
1195
+ var excluded = -sum;
1196
+ var objs = document.querySelectorAll(obj.tagsums);
1197
+ for(var i = 0; i < objs.length; i++) excluded += parseInt(objs[i].innerText);
1198
+ obj.querySelector('.excluded').innerText = excluded;
1199
+ var current = obj.querySelector('.current');
1200
+ if(sum == 0) {
1201
+ current.innerText = 1;
1202
+ } else {if(parseInt(current.innerText) > sum
1203
+ ) current.innerText = sum;
1204
+ };
1205
+ };
1206
+
1207
+ initializeNavigations = function() {
1208
+ for(var i = 1, obj; obj = document.getElementById('user-feature-navigation' + i); i++
1209
+ ) initializeNavigation(obj);
1210
+ for(var i = 1, obj; obj = document.getElementById('dev-feature-navigation' + i); i++
1211
+ ) initializeNavigation(obj);
1212
+ for(var i = 1, obj; obj = document.getElementById('anchor-navigation' + i); i++
1213
+ ) initializeNavigation(obj);
1214
+ };
1215
+
1216
+ getFeatureNodeFromId = function(id) {
1217
+ var obj = document.getElementById(id);
1218
+ if(!obj) return null;
1219
+ while(true) {
1220
+ if(obj.className == 'feature') return obj;
1221
+ obj = obj.parentNode;
1222
+ if(!obj) return null;
1223
+ }
1224
+ };
1225
+
1226
+ getIdFromObj = function(obj) {
1227
+ while(true) {
1228
+ if(obj.id) return obj.id;
1229
+ obj = obj.parentNode;
1230
+ if(!obj) return null;
1231
+ }
1232
+ };
1233
+
1234
+ hide = function(obj, bool) {obj.style.display = bool ? 'none' : null;};
1235
+
1236
+ inactivate = function(obj, bool) {obj.style.opacity = bool ? 0.2 : null;};
1237
+
1238
+ mark = function(obj, bool) {return obj.marking = bool;};
1239
+
1240
+ toggleMarking = function(obj) {return obj.marking = !obj.marking;};
1241
+
1242
+ hideByTag = function(obj, tag, bool) {
1243
+ if(bool) {obj.hiddenFor[tag] = true;} else {delete obj.hiddenFor[tag];};
1244
+ hide(obj, Object.keys(obj.hiddenFor).length);
1245
+ };
1246
+
1247
+ foldModuleContents = function(obj, bool){
1248
+ obj.firstChild.setAttribute('folded', bool);
1249
+ var objs = obj.childNodes;
1250
+ foldFeatureContents(objs[0], bool);
1251
+ // From the second children.
1252
+ for (var i = 1; i < objs.length; i++) hideByTag(objs[i], 'folded', bool);
1253
+ return bool;
1254
+ };
1255
+
1256
+ foldFeatureContents = function(obj, bool){
1257
+ obj.setAttribute('folded', bool);
1258
+ hide(obj.firstChild.nextSibling, bool);
1259
+ return bool;
1260
+ };
1261
+
1262
+ displayMode = function(bool1, bool2) {
1263
+ var objs = document.getElementsByClassName('module');
1264
+ for(var i = 0; i < objs.length; i++) foldModuleContents(objs[i], mark(objs[i], bool1));
1265
+ // `[onclick]`: Features with `type` `:module_as_constant` are not clickable.
1266
+ // `:not(:first-child)`: Don't fold module headers here.
1267
+ var objs = document.querySelectorAll('.feature[onclick]:not(:first-child)');
1268
+ for(var i = 0; i < objs.length; i++) foldFeatureContents(objs[i], mark(objs[i], bool2));
1269
+ initializeNavigations();
1270
+ };
1271
+
1272
+ toggleModuleContents = function(feature) {
1273
+ var module = feature.parentNode;
1274
+ var bool = foldModuleContents(module, toggleMarking(module));
1275
+ if(bool) {
1276
+ module.scrollIntoView();
1277
+ window.onhashchange();
1278
+ }
1279
+ initializeNavigations();
1280
+ };
1281
+
1282
+ toggleFeatureContents = function(feature) {
1283
+ var bool = foldFeatureContents(feature, toggleMarking(feature));
1284
+ if(bool) {
1285
+ feature.scrollIntoView();
1286
+ window.onhashchange();
1287
+ }
1288
+ initializeNavigations();
1289
+ };
1290
+
1291
+ toggleUserItems = function(button) {
1292
+ // recordScrollPosition();
1293
+ var bool = toggleMarking(button);
1294
+ inactivate(button, bool);
1295
+ objs = document.getElementsByClassName('user-item');
1296
+ for(i = 0; i < objs.length; i++) hide(objs[i], bool);
1297
+ initializeNavigations();
1298
+ // resumeScrollPosition();
1299
+ };
1300
+
1301
+ toggleFeatures = function(button, tag, navigation) {
1302
+ // recordScrollPosition();
1303
+ var bool = toggleMarking(button);
1304
+ inactivate(button, bool);
1305
+ inactivate(document.getElementById('tagsum-' + tag), bool);
1306
+ for(var i = 1, obj; obj = getFeatureNodeFromId(tag + i); i ++) hideByTag(obj, tag, bool);
1307
+ navigation = document.getElementById(navigation);
1308
+ initializeNavigations();
1309
+ // resumeScrollPosition();
1310
+ };
1311
+
1312
+ toggleAnchors = function(button, tag, navigation) {
1313
+ // recordScrollPosition();
1314
+ var bool = toggleMarking(button);
1315
+ inactivate(button, bool);
1316
+ inactivate(document.getElementById('tagsum-' + tag), bool);
1317
+ for(var i = 1, obj; obj = document.getElementById(tag + i); i ++) hide(obj, bool);
1318
+ navigation = document.getElementById(navigation);
1319
+ initializeNavigation(navigation);
1320
+ // resumeScrollPosition();
1321
+ };
1322
+
1323
+ navigateTag = function(navigation, d) {
1324
+ var n = navigation.features.length;
1325
+ if(n == 0) return;
1326
+ var old = document.getElementById('current');
1327
+ if(old) old.removeAttribute('id');
1328
+ var current = navigation.querySelector('.current');
1329
+ current.id = 'current';
1330
+ var i = parseInt(current.innerText) + d;
1331
+ if(i < 1) i = 1;
1332
+ if(i > n) i = n;
1333
+ current.innerText = i;
1334
+ location.hash = getIdFromObj(navigation.features[i - 1]);
1335
+ };
1336
+
1337
+ //var lastToggled =
1338
+ //var lastViewPort =
1339
+ recordScrollPosition = function() {
1340
+ // main.scrollTop = navigation.features[i - 1].offsetTop - main.offsetTop;
1341
+ /*
1342
+ foo = function(obj) {
1343
+ var ref = window.scrollY - window.pageYOffset + document.documentElement.clientTop;
1344
+ var checkChildDivs = function() {
1345
+ var children = obj.childNodes;
1346
+ if (children.length) {[].forEach.call(children, function(e, i, a) {
1347
+ if (e.toString() === "[object HTMLDivElement]") {
1348
+ // the top of the div relative to the document
1349
+ // minus the height of window hidden above the top of the screen
1350
+ var top = e.getBoundingClientRect().top;
1351
+ // top and bottom posns relative to the top of the screen
1352
+ // the top and bottom distances of the element relative to the top of the screen
1353
+ // the div overlaps the screen top
1354
+ if ((top <= ref) && (ref <= top + e.offsetHeight)) {
1355
+ obj = e;
1356
+ checkChildDivs();
1357
+ return false;
1358
+ }
1359
+ }
1360
+ });}
1361
+ };
1362
+ checkChildDivs();
1363
+ return obj;
1364
+ };
1365
+ */
1366
+ };
1367
+
1368
+ resumeScrollPosition = function() {
1369
+ };
1370
+
1371
+ coverage = function(obj){
1372
+ alert("Sorry, this function is not implemented.");
1373
+ // alert(obj.nextSibling.contentDocument.querySelector('body').innerText);
1374
+ // var f = obj.dataset.file;
1375
+ };
1376
+ </script></body></html>