yard 0.7.5 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of yard might be problematic. Click here for more details.
- data/.yardopts +10 -2
- data/ChangeLog +1263 -38
- data/LEGAL +5 -5
- data/LICENSE +1 -1
- data/README.md +91 -82
- data/Rakefile +6 -6
- data/benchmarks/builtins_vs_eval.rb +1 -1
- data/benchmarks/erb_vs_erubis.rb +4 -4
- data/benchmarks/generation.rb +5 -5
- data/benchmarks/parsing.rb +2 -2
- data/benchmarks/registry_store_types.rb +48 -0
- data/bin/yard +9 -1
- data/bin/yardoc +9 -1
- data/bin/yri +10 -2
- data/docs/CodeObjects.md +10 -10
- data/docs/GettingStarted.md +85 -83
- data/docs/Handlers.md +21 -21
- data/docs/Overview.md +7 -7
- data/docs/Parser.md +30 -30
- data/docs/Tags.md +250 -554
- data/docs/TagsArch.md +123 -0
- data/docs/Templates.md +58 -80
- data/docs/WhatsNew.md +378 -133
- data/docs/templates/default/fulldoc/html/full_list_tag.erb +7 -0
- data/docs/templates/default/fulldoc/html/setup.rb +6 -0
- data/docs/templates/default/layout/html/setup.rb +8 -0
- data/docs/templates/default/layout/html/tag_list.erb +11 -0
- data/docs/templates/default/yard_tags/html/list.erb +18 -0
- data/docs/templates/default/yard_tags/html/setup.rb +27 -0
- data/docs/templates/plugin.rb +65 -0
- data/lib/yard.rb +1 -10
- data/lib/yard/autoload.rb +75 -27
- data/lib/yard/cli/command.rb +5 -2
- data/lib/yard/cli/command_parser.rb +3 -2
- data/lib/yard/cli/diff.rb +1 -1
- data/lib/yard/cli/i18n.rb +69 -0
- data/lib/yard/cli/list.rb +1 -1
- data/lib/yard/cli/server.rb +30 -7
- data/lib/yard/cli/stats.rb +5 -6
- data/lib/yard/cli/yardoc.rb +95 -45
- data/lib/yard/cli/yri.rb +24 -3
- data/lib/yard/code_objects/base.rb +35 -4
- data/lib/yard/code_objects/extra_file_object.rb +1 -1
- data/lib/yard/code_objects/macro_object.rb +56 -99
- data/lib/yard/code_objects/method_object.rb +44 -6
- data/lib/yard/config.rb +18 -8
- data/lib/yard/core_ext/symbol_hash.rb +1 -1
- data/lib/yard/docstring.rb +45 -85
- data/lib/yard/docstring_parser.rb +269 -0
- data/lib/yard/handlers/base.rb +129 -118
- data/lib/yard/handlers/c/alias_handler.rb +15 -0
- data/lib/yard/handlers/c/attribute_handler.rb +13 -0
- data/lib/yard/handlers/c/base.rb +110 -0
- data/lib/yard/handlers/c/class_handler.rb +26 -0
- data/lib/yard/handlers/c/constant_handler.rb +12 -0
- data/lib/yard/handlers/c/handler_methods.rb +165 -0
- data/lib/yard/handlers/c/init_handler.rb +16 -0
- data/lib/yard/handlers/c/method_handler.rb +35 -0
- data/lib/yard/handlers/c/mixin_handler.rb +13 -0
- data/lib/yard/handlers/c/module_handler.rb +16 -0
- data/lib/yard/handlers/c/override_comment_handler.rb +22 -0
- data/lib/yard/handlers/c/path_handler.rb +10 -0
- data/lib/yard/handlers/c/struct_handler.rb +12 -0
- data/lib/yard/handlers/c/symbol_handler.rb +7 -0
- data/lib/yard/handlers/processor.rb +41 -30
- data/lib/yard/handlers/ruby/alias_handler.rb +0 -2
- data/lib/yard/handlers/ruby/attribute_handler.rb +16 -17
- data/lib/yard/handlers/ruby/base.rb +10 -6
- data/lib/yard/handlers/ruby/comment_handler.rb +9 -0
- data/lib/yard/handlers/ruby/dsl_handler.rb +14 -0
- data/lib/yard/handlers/ruby/dsl_handler_methods.rb +71 -0
- data/lib/yard/handlers/ruby/legacy/alias_handler.rb +0 -3
- data/lib/yard/handlers/ruby/legacy/attribute_handler.rb +16 -17
- data/lib/yard/handlers/ruby/legacy/base.rb +28 -6
- data/lib/yard/handlers/ruby/legacy/comment_handler.rb +9 -0
- data/lib/yard/handlers/ruby/legacy/dsl_handler.rb +16 -0
- data/lib/yard/handlers/ruby/legacy/method_handler.rb +0 -2
- data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +1 -1
- data/lib/yard/handlers/ruby/legacy/module_function_handler.rb +18 -0
- data/lib/yard/handlers/ruby/method_handler.rb +10 -15
- data/lib/yard/handlers/ruby/mixin_handler.rb +1 -1
- data/lib/yard/handlers/ruby/module_function_handler.rb +26 -0
- data/lib/yard/handlers/ruby/struct_handler_methods.rb +3 -2
- data/lib/yard/i18n/pot_generator.rb +281 -0
- data/lib/yard/i18n/text.rb +72 -0
- data/lib/yard/logging.rb +3 -7
- data/lib/yard/options.rb +216 -0
- data/lib/yard/parser/c/c_parser.rb +225 -0
- data/lib/yard/parser/c/comment_parser.rb +131 -0
- data/lib/yard/parser/c/statement.rb +63 -0
- data/lib/yard/parser/ruby/ast_node.rb +91 -1
- data/lib/yard/parser/ruby/legacy/ruby_parser.rb +1 -0
- data/lib/yard/parser/ruby/legacy/statement.rb +7 -2
- data/lib/yard/parser/ruby/legacy/statement_list.rb +13 -22
- data/lib/yard/parser/ruby/ruby_parser.rb +87 -26
- data/lib/yard/parser/source_parser.rb +89 -88
- data/lib/yard/rake/yardoc_task.rb +1 -1
- data/lib/yard/registry.rb +21 -10
- data/lib/yard/registry_store.rb +48 -0
- data/lib/yard/serializers/file_system_serializer.rb +18 -20
- data/lib/yard/serializers/yardoc_serializer.rb +1 -0
- data/lib/yard/server/adapter.rb +2 -2
- data/lib/yard/server/commands/base.rb +1 -1
- data/lib/yard/server/commands/display_object_command.rb +13 -6
- data/lib/yard/server/commands/frames_command.rb +4 -21
- data/lib/yard/server/commands/library_command.rb +57 -11
- data/lib/yard/server/commands/list_command.rb +10 -34
- data/lib/yard/server/commands/search_command.rb +8 -2
- data/lib/yard/server/doc_server_helper.rb +34 -0
- data/lib/yard/server/rack_adapter.rb +5 -1
- data/lib/yard/server/router.rb +4 -10
- data/lib/yard/server/static_caching.rb +2 -2
- data/lib/yard/server/templates/default/fulldoc/html/css/custom.css +2 -2
- data/lib/yard/server/templates/default/fulldoc/html/js/live.js +0 -15
- data/lib/yard/server/templates/default/layout/html/breadcrumb.erb +3 -3
- data/lib/yard/server/templates/default/layout/html/script_setup.erb +8 -0
- data/lib/yard/server/templates/doc_server/processing/html/processing.erb +1 -1
- data/lib/yard/server/templates/doc_server/search/html/setup.rb +1 -1
- data/lib/yard/tags/default_factory.rb +31 -4
- data/lib/yard/tags/directives.rb +593 -0
- data/lib/yard/tags/library.rb +437 -35
- data/lib/yard/templates/engine.rb +17 -12
- data/lib/yard/templates/helpers/base_helper.rb +8 -2
- data/lib/yard/templates/helpers/html_helper.rb +57 -14
- data/lib/yard/templates/helpers/markup/rdoc_markup.rb +1 -1
- data/lib/yard/templates/helpers/markup_helper.rb +9 -9
- data/lib/yard/templates/helpers/text_helper.rb +2 -2
- data/lib/yard/templates/template.rb +42 -13
- data/lib/yard/templates/template_options.rb +81 -0
- data/spec/cli/command_parser_spec.rb +4 -4
- data/spec/cli/command_spec.rb +3 -3
- data/spec/cli/config_spec.rb +13 -13
- data/spec/cli/diff_spec.rb +13 -10
- data/spec/cli/gems_spec.rb +12 -12
- data/spec/cli/help_spec.rb +2 -2
- data/spec/cli/i18n_spec.rb +111 -0
- data/spec/cli/server_spec.rb +66 -18
- data/spec/cli/stats_spec.rb +15 -15
- data/spec/cli/yardoc_spec.rb +124 -97
- data/spec/cli/yri_spec.rb +14 -12
- data/spec/code_objects/base_spec.rb +104 -46
- data/spec/code_objects/class_object_spec.rb +33 -33
- data/spec/code_objects/code_object_list_spec.rb +5 -5
- data/spec/code_objects/constants_spec.rb +4 -3
- data/spec/code_objects/extra_file_object_spec.rb +19 -19
- data/spec/code_objects/macro_object_spec.rb +31 -37
- data/spec/code_objects/method_object_spec.rb +46 -23
- data/spec/code_objects/module_object_spec.rb +16 -16
- data/spec/code_objects/namespace_object_spec.rb +6 -6
- data/spec/code_objects/proxy_spec.rb +19 -19
- data/spec/config_spec.rb +33 -24
- data/spec/core_ext/array_spec.rb +1 -1
- data/spec/core_ext/file_spec.rb +8 -8
- data/spec/core_ext/hash_spec.rb +1 -1
- data/spec/core_ext/insertion_spec.rb +3 -3
- data/spec/core_ext/module_spec.rb +1 -1
- data/spec/core_ext/string_spec.rb +6 -6
- data/spec/core_ext/symbol_hash_spec.rb +11 -11
- data/spec/docstring_parser_spec.rb +207 -0
- data/spec/docstring_spec.rb +33 -146
- data/spec/handlers/alias_handler_spec.rb +14 -14
- data/spec/handlers/attribute_handler_spec.rb +20 -20
- data/spec/handlers/base_spec.rb +16 -16
- data/spec/handlers/c/alias_handler_spec.rb +33 -0
- data/spec/handlers/c/attribute_handler_spec.rb +40 -0
- data/spec/handlers/c/class_handler_spec.rb +64 -0
- data/spec/handlers/c/constant_handler_spec.rb +68 -0
- data/spec/handlers/c/init_handler_spec.rb +36 -0
- data/spec/handlers/c/method_handler_spec.rb +228 -0
- data/spec/handlers/c/mixin_handler_spec.rb +27 -0
- data/spec/handlers/c/module_handler_spec.rb +38 -0
- data/spec/handlers/c/override_comment_handler_spec.rb +43 -0
- data/spec/handlers/c/path_handler_spec.rb +35 -0
- data/spec/handlers/c/spec_helper.rb +11 -0
- data/spec/handlers/c/struct_handler_spec.rb +15 -0
- data/spec/handlers/class_condition_handler_spec.rb +10 -10
- data/spec/handlers/class_handler_spec.rb +38 -38
- data/spec/handlers/class_variable_handler_spec.rb +1 -1
- data/spec/handlers/constant_handler_spec.rb +7 -7
- data/spec/handlers/{macro_handler_spec.rb → dsl_handler_spec.rb} +72 -53
- data/spec/handlers/examples/alias_handler_001.rb.txt +5 -5
- data/spec/handlers/examples/class_condition_handler_001.rb.txt +9 -9
- data/spec/handlers/examples/class_handler_001.rb.txt +1 -1
- data/spec/handlers/examples/dsl_handler_001.rb.txt +110 -0
- data/spec/handlers/examples/exception_handler_001.rb.txt +14 -14
- data/spec/handlers/examples/method_condition_handler_001.rb.txt +2 -2
- data/spec/handlers/examples/method_handler_001.rb.txt +16 -16
- data/spec/handlers/examples/mixin_handler_001.rb.txt +8 -4
- data/spec/handlers/examples/private_constant_handler_001.rb.txt +1 -1
- data/spec/handlers/examples/visibility_handler_001.rb.txt +3 -3
- data/spec/handlers/examples/yield_handler_001.rb.txt +13 -14
- data/spec/handlers/exception_handler_spec.rb +9 -9
- data/spec/handlers/extend_handler_spec.rb +2 -2
- data/spec/handlers/legacy_base_spec.rb +34 -34
- data/spec/handlers/method_condition_handler_spec.rb +2 -2
- data/spec/handlers/method_handler_spec.rb +33 -33
- data/spec/handlers/mixin_handler_spec.rb +13 -9
- data/spec/handlers/module_function_handler_spec.rb +82 -0
- data/spec/handlers/module_handler_spec.rb +6 -6
- data/spec/handlers/private_constant_handler_spec.rb +3 -3
- data/spec/handlers/processor_spec.rb +5 -5
- data/spec/handlers/ruby/base_spec.rb +10 -6
- data/spec/handlers/ruby/legacy/base_spec.rb +11 -7
- data/spec/handlers/spec_helper.rb +2 -3
- data/spec/handlers/visibility_handler_spec.rb +6 -6
- data/spec/handlers/yield_handler_spec.rb +8 -8
- data/spec/i18n/pot_generator_spec.rb +244 -0
- data/spec/i18n/text_spec.rb +69 -0
- data/spec/options_spec.rb +160 -0
- data/spec/parser/base_spec.rb +3 -3
- data/spec/parser/c_parser_spec.rb +31 -257
- data/spec/parser/examples/array.c.txt +187 -187
- data/spec/parser/examples/extrafile.c.txt +1 -1
- data/spec/parser/examples/override.c.txt +1 -1
- data/spec/parser/ruby/ast_node_spec.rb +1 -1
- data/spec/parser/ruby/legacy/statement_list_spec.rb +24 -24
- data/spec/parser/ruby/legacy/token_list_spec.rb +7 -7
- data/spec/parser/ruby/ruby_parser_spec.rb +56 -34
- data/spec/parser/source_parser_spec.rb +125 -65
- data/spec/parser/tag_parsing_spec.rb +4 -4
- data/spec/rake/yardoc_task_spec.rb +10 -8
- data/spec/registry_spec.rb +65 -36
- data/spec/registry_store_spec.rb +90 -40
- data/spec/serializers/file_system_serializer_spec.rb +12 -12
- data/spec/serializers/yardoc_serializer_spec.rb +2 -2
- data/spec/server/adapter_spec.rb +3 -3
- data/spec/server/commands/base_spec.rb +8 -8
- data/spec/server/commands/library_command_spec.rb +3 -3
- data/spec/server/commands/static_file_command_spec.rb +7 -7
- data/spec/server/doc_server_helper_spec.rb +1 -1
- data/spec/server/doc_server_serializer_spec.rb +6 -6
- data/spec/server/rack_adapter_spec.rb +3 -3
- data/spec/server/router_spec.rb +19 -19
- data/spec/server/static_caching_spec.rb +4 -4
- data/spec/spec_helper.rb +7 -7
- data/spec/tags/default_factory_spec.rb +24 -16
- data/spec/tags/directives_spec.rb +422 -0
- data/spec/tags/library_spec.rb +15 -4
- data/spec/tags/overload_tag_spec.rb +6 -6
- data/spec/tags/ref_tag_list_spec.rb +8 -8
- data/spec/templates/class_spec.rb +7 -7
- data/spec/templates/constant_spec.rb +7 -7
- data/spec/templates/engine_spec.rb +28 -36
- data/spec/templates/examples/class001.html +108 -108
- data/spec/templates/examples/class002.html +17 -17
- data/spec/templates/examples/constant001.txt +1 -1
- data/spec/templates/examples/method001.html +45 -45
- data/spec/templates/examples/method002.html +25 -25
- data/spec/templates/examples/method003.html +60 -60
- data/spec/templates/examples/method004.html +7 -7
- data/spec/templates/examples/method005.html +28 -28
- data/spec/templates/examples/module001.html +321 -321
- data/spec/templates/examples/module001.txt +1 -1
- data/spec/templates/examples/module002.html +130 -130
- data/spec/templates/examples/module003.html +74 -74
- data/spec/templates/examples/module004.html +388 -0
- data/spec/templates/helpers/base_helper_spec.rb +32 -32
- data/spec/templates/helpers/html_helper_spec.rb +87 -68
- data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +9 -9
- data/spec/templates/helpers/markup/rdoc_markup_spec.rb +16 -16
- data/spec/templates/helpers/markup_helper_spec.rb +31 -28
- data/spec/templates/helpers/method_helper_spec.rb +7 -7
- data/spec/templates/helpers/shared_signature_examples.rb +9 -7
- data/spec/templates/helpers/text_helper_spec.rb +3 -3
- data/spec/templates/method_spec.rb +13 -13
- data/spec/templates/module_spec.rb +70 -24
- data/spec/templates/onefile_spec.rb +32 -15
- data/spec/templates/section_spec.rb +23 -23
- data/spec/templates/spec_helper.rb +31 -1
- data/spec/templates/tag_spec.rb +5 -5
- data/spec/templates/template_spec.rb +54 -46
- data/spec/verifier_spec.rb +5 -5
- data/templates/default/class/setup.rb +2 -2
- data/templates/default/docstring/html/abstract.erb +1 -1
- data/templates/default/docstring/html/note.erb +1 -1
- data/templates/default/docstring/html/private.erb +1 -1
- data/templates/default/docstring/html/todo.erb +1 -1
- data/templates/default/docstring/setup.rb +2 -2
- data/templates/default/fulldoc/html/css/full_list.css +4 -2
- data/templates/default/fulldoc/html/css/style.css +50 -44
- data/templates/default/fulldoc/html/frames.erb +21 -6
- data/templates/default/fulldoc/html/full_list.erb +5 -3
- data/templates/default/fulldoc/html/{full_list_files.erb → full_list_file.erb} +0 -0
- data/templates/default/fulldoc/html/js/app.js +29 -26
- data/templates/default/fulldoc/html/js/full_list.js +9 -9
- data/templates/default/fulldoc/html/js/jquery.js +4 -16
- data/templates/default/fulldoc/html/setup.rb +42 -38
- data/templates/default/layout/dot/header.erb +1 -1
- data/templates/default/layout/html/breadcrumb.erb +6 -6
- data/templates/default/layout/html/files.erb +1 -1
- data/templates/default/layout/html/footer.erb +1 -1
- data/templates/default/layout/html/headers.erb +3 -6
- data/templates/default/layout/html/index.erb +1 -1
- data/templates/default/layout/html/layout.erb +3 -7
- data/templates/default/layout/html/objects.erb +1 -1
- data/templates/default/layout/html/script_setup.erb +5 -0
- data/templates/default/layout/html/search.erb +4 -1
- data/templates/default/layout/html/setup.rb +8 -8
- data/templates/default/method_details/html/method_signature.erb +10 -3
- data/templates/default/method_details/setup.rb +1 -0
- data/templates/default/module/dot/info.erb +1 -1
- data/templates/default/module/dot/setup.rb +2 -2
- data/templates/default/module/html/attribute_details.erb +1 -1
- data/templates/default/module/html/children.erb +1 -1
- data/templates/default/module/html/defines.erb +1 -1
- data/templates/default/module/html/inherited_methods.erb +5 -4
- data/templates/default/module/html/item_summary.erb +15 -5
- data/templates/default/module/html/method_details_list.erb +2 -2
- data/templates/default/module/setup.rb +25 -12
- data/templates/default/module/text/setup.rb +1 -1
- data/templates/default/onefile/html/layout.erb +1 -1
- data/templates/default/onefile/html/setup.rb +2 -2
- data/templates/default/tags/html/example.erb +4 -2
- data/templates/default/tags/html/option.erb +1 -1
- data/templates/default/tags/html/overload.erb +1 -1
- data/templates/default/tags/html/see.erb +1 -1
- data/templates/default/tags/html/tag.erb +1 -1
- data/templates/default/tags/setup.rb +4 -3
- data/templates/guide/fulldoc/html/css/style.css +8 -8
- data/templates/guide/fulldoc/html/js/app.js +6 -6
- data/templates/guide/fulldoc/html/setup.rb +12 -12
- data/templates/guide/layout/html/layout.erb +11 -11
- data/templates/guide/layout/html/setup.rb +9 -9
- data/templates/guide/method/html/header.erb +2 -2
- data/templates/guide/method/html/setup.rb +1 -1
- metadata +68 -18
- data/bin/yard-graph +0 -4
- data/bin/yard-server +0 -4
- data/docs/Glossary.md +0 -12
- data/lib/yard/handlers/ruby/legacy/macro_handler.rb +0 -39
- data/lib/yard/handlers/ruby/macro_handler.rb +0 -40
- data/lib/yard/handlers/ruby/macro_handler_methods.rb +0 -131
- data/lib/yard/parser/c_parser.rb +0 -497
- data/lib/yard/server/templates/default/layout/html/headers.erb +0 -16
- data/lib/yard/server/templates/doc_server/frames/html/frames.erb +0 -13
- data/lib/yard/server/templates/doc_server/frames/html/setup.rb +0 -3
- data/lib/yard/server/templates/doc_server/full_list/html/full_list.erb +0 -34
- data/lib/yard/server/templates/doc_server/full_list/html/setup.rb +0 -20
- data/spec/handlers/examples/macro_handler_001.rb.txt +0 -83
@@ -95,7 +95,7 @@ memfill(register VALUE *mem, register long size, register VALUE val)
|
|
95
95
|
ARY_SET_HEAP_LEN(ary, n); \
|
96
96
|
} \
|
97
97
|
assert(RARRAY_LEN(ary) == n); \
|
98
|
-
} while (0)
|
98
|
+
} while (0)
|
99
99
|
#define ARY_INCREASE_PTR(ary, n) do { \
|
100
100
|
assert(!ARY_EMBED_P(ary)); \
|
101
101
|
assert(!OBJ_FROZEN(ary)); \
|
@@ -144,30 +144,30 @@ static void
|
|
144
144
|
ary_resize_capa(VALUE ary, long capacity)
|
145
145
|
{
|
146
146
|
assert(RARRAY_LEN(ary) <= capacity);
|
147
|
-
assert(!OBJ_FROZEN(ary));
|
148
|
-
assert(!ARY_SHARED_P(ary));
|
147
|
+
assert(!OBJ_FROZEN(ary));
|
148
|
+
assert(!ARY_SHARED_P(ary));
|
149
149
|
if (capacity > RARRAY_EMBED_LEN_MAX) {
|
150
150
|
if (ARY_EMBED_P(ary)) {
|
151
|
-
long len = ARY_EMBED_LEN(ary);
|
151
|
+
long len = ARY_EMBED_LEN(ary);
|
152
152
|
VALUE *ptr = ALLOC_N(VALUE, (capacity));
|
153
|
-
MEMCPY(ptr, ARY_EMBED_PTR(ary), VALUE, len);
|
154
|
-
FL_UNSET_EMBED(ary);
|
155
|
-
ARY_SET_PTR(ary, ptr);
|
156
|
-
ARY_SET_HEAP_LEN(ary, len);
|
153
|
+
MEMCPY(ptr, ARY_EMBED_PTR(ary), VALUE, len);
|
154
|
+
FL_UNSET_EMBED(ary);
|
155
|
+
ARY_SET_PTR(ary, ptr);
|
156
|
+
ARY_SET_HEAP_LEN(ary, len);
|
157
157
|
}
|
158
|
-
else {
|
158
|
+
else {
|
159
159
|
REALLOC_N(RARRAY(ary)->as.heap.ptr, VALUE, (capacity));
|
160
160
|
}
|
161
|
-
ARY_SET_CAPA(ary, (capacity));
|
161
|
+
ARY_SET_CAPA(ary, (capacity));
|
162
162
|
}
|
163
163
|
else {
|
164
164
|
if (!ARY_EMBED_P(ary)) {
|
165
|
-
long len = RARRAY_LEN(ary);
|
166
|
-
VALUE *ptr = RARRAY_PTR(ary);
|
167
|
-
MEMCPY(RARRAY(ary)->as.ary, ptr, VALUE, len);
|
168
|
-
FL_SET_EMBED(ary);
|
169
|
-
ARY_SET_LEN(ary, len);
|
170
|
-
xfree(ptr);
|
165
|
+
long len = RARRAY_LEN(ary);
|
166
|
+
VALUE *ptr = RARRAY_PTR(ary);
|
167
|
+
MEMCPY(RARRAY(ary)->as.ary, ptr, VALUE, len);
|
168
|
+
FL_SET_EMBED(ary);
|
169
|
+
ARY_SET_LEN(ary, len);
|
170
|
+
xfree(ptr);
|
171
171
|
}
|
172
172
|
}
|
173
173
|
}
|
@@ -431,11 +431,11 @@ rb_check_array_type(VALUE ary)
|
|
431
431
|
* Try to convert <i>obj</i> into an array, using to_ary method.
|
432
432
|
* Returns converted array or nil if <i>obj</i> cannot be converted
|
433
433
|
* for any reason. This method is to check if an argument is an
|
434
|
-
* array.
|
434
|
+
* array.
|
435
435
|
*
|
436
436
|
* Array.try_convert([1]) # => [1]
|
437
437
|
* Array.try_convert("1") # => nil
|
438
|
-
*
|
438
|
+
*
|
439
439
|
* if tmp = Array.try_convert(arg)
|
440
440
|
* # the argument is an array
|
441
441
|
* elsif tmp = String.try_convert(arg)
|
@@ -469,22 +469,22 @@ rb_ary_s_try_convert(VALUE dummy, VALUE ary)
|
|
469
469
|
* Array.new
|
470
470
|
* Array.new(2)
|
471
471
|
* Array.new(5, "A")
|
472
|
-
*
|
472
|
+
*
|
473
473
|
* # only one copy of the object is created
|
474
474
|
* a = Array.new(2, Hash.new)
|
475
475
|
* a[0]['cat'] = 'feline'
|
476
476
|
* a
|
477
477
|
* a[1]['cat'] = 'Felix'
|
478
478
|
* a
|
479
|
-
*
|
479
|
+
*
|
480
480
|
* # here multiple copies are created
|
481
481
|
* a = Array.new(2) { Hash.new }
|
482
482
|
* a[0]['cat'] = 'feline'
|
483
483
|
* a
|
484
|
-
*
|
484
|
+
*
|
485
485
|
* squares = Array.new(5) {|i| i*i}
|
486
486
|
* squares
|
487
|
-
*
|
487
|
+
*
|
488
488
|
* copy = Array.new(squares)
|
489
489
|
*/
|
490
490
|
|
@@ -544,8 +544,8 @@ rb_ary_initialize(int argc, VALUE *argv, VALUE ary)
|
|
544
544
|
}
|
545
545
|
|
546
546
|
|
547
|
-
/*
|
548
|
-
* Returns a new array populated with the given objects.
|
547
|
+
/*
|
548
|
+
* Returns a new array populated with the given objects.
|
549
549
|
*
|
550
550
|
* Array.[]( 1, 'a', /^A/ )
|
551
551
|
* Array[ 1, 'a', /^A/ ]
|
@@ -666,7 +666,7 @@ ary_take_first_or_last(int argc, VALUE *argv, VALUE ary, enum ary_take_pos_flags
|
|
666
666
|
/*
|
667
667
|
* call-seq:
|
668
668
|
* array << obj -> array
|
669
|
-
*
|
669
|
+
*
|
670
670
|
* Append---Pushes the given object on to the end of this array. This
|
671
671
|
* expression returns the array itself, so several appends
|
672
672
|
* may be chained together.
|
@@ -683,16 +683,16 @@ rb_ary_push(VALUE ary, VALUE item)
|
|
683
683
|
return ary;
|
684
684
|
}
|
685
685
|
|
686
|
-
/*
|
686
|
+
/*
|
687
687
|
* call-seq:
|
688
688
|
* array.push(obj, ... ) -> array
|
689
|
-
*
|
689
|
+
*
|
690
690
|
* Append---Pushes the given object(s) on to the end of this array. This
|
691
691
|
* expression returns the array itself, so several appends
|
692
692
|
* may be chained together.
|
693
693
|
*
|
694
694
|
* a = [ "a", "b", "c" ]
|
695
|
-
* a.push("d", "e", "f")
|
695
|
+
* a.push("d", "e", "f")
|
696
696
|
* #=> ["a", "b", "c", "d", "e", "f"]
|
697
697
|
*/
|
698
698
|
|
@@ -727,13 +727,13 @@ rb_ary_pop(VALUE ary)
|
|
727
727
|
* call-seq:
|
728
728
|
* array.pop -> obj or nil
|
729
729
|
* array.pop(n) -> array
|
730
|
-
*
|
730
|
+
*
|
731
731
|
* Removes the last element from <i>self</i> and returns it, or
|
732
732
|
* <code>nil</code> if the array is empty.
|
733
733
|
*
|
734
734
|
* If a number _n_ is given, returns an array of the last n elements
|
735
735
|
* (or less) just like <code>array.slice!(-n, n)</code> does.
|
736
|
-
*
|
736
|
+
*
|
737
737
|
* a = [ "a", "b", "c", "d" ]
|
738
738
|
* a.pop #=> "d"
|
739
739
|
* a.pop(2) #=> ["b", "c"]
|
@@ -784,14 +784,14 @@ rb_ary_shift(VALUE ary)
|
|
784
784
|
* call-seq:
|
785
785
|
* array.shift -> obj or nil
|
786
786
|
* array.shift(n) -> array
|
787
|
-
*
|
787
|
+
*
|
788
788
|
* Returns the first element of <i>self</i> and removes it (shifting all
|
789
789
|
* other elements down by one). Returns <code>nil</code> if the array
|
790
790
|
* is empty.
|
791
791
|
*
|
792
792
|
* If a number _n_ is given, returns an array of the first n elements
|
793
793
|
* (or less) just like <code>array.slice!(0, n)</code> does.
|
794
|
-
*
|
794
|
+
*
|
795
795
|
* args = [ "-m", "-q", "filename" ]
|
796
796
|
* args.shift #=> "-m"
|
797
797
|
* args #=> ["-q", "filename"]
|
@@ -828,10 +828,10 @@ rb_ary_shift_m(int argc, VALUE *argv, VALUE ary)
|
|
828
828
|
/*
|
829
829
|
* call-seq:
|
830
830
|
* array.unshift(obj, ...) -> array
|
831
|
-
*
|
831
|
+
*
|
832
832
|
* Prepends objects to the front of <i>array</i>.
|
833
833
|
* other elements up one.
|
834
|
-
*
|
834
|
+
*
|
835
835
|
* a = [ "b", "c", "d" ]
|
836
836
|
* a.unshift("a") #=> ["a", "b", "c", "d"]
|
837
837
|
* a.unshift(1, 2) #=> [ 1, 2, "a", "b", "c", "d"]
|
@@ -852,7 +852,7 @@ rb_ary_unshift_m(int argc, VALUE *argv, VALUE ary)
|
|
852
852
|
MEMMOVE(RARRAY_PTR(ary) + argc, RARRAY_PTR(ary), VALUE, len);
|
853
853
|
MEMCPY(RARRAY_PTR(ary), argv, VALUE, argc);
|
854
854
|
ARY_INCREASE_LEN(ary, argc);
|
855
|
-
|
855
|
+
|
856
856
|
return ary;
|
857
857
|
}
|
858
858
|
|
@@ -899,7 +899,7 @@ rb_ary_subseq(VALUE ary, long beg, long len)
|
|
899
899
|
return ary_make_partial(ary, klass, beg, len);
|
900
900
|
}
|
901
901
|
|
902
|
-
/*
|
902
|
+
/*
|
903
903
|
* call-seq:
|
904
904
|
* array[index] -> obj or nil
|
905
905
|
* array[start, length] -> an_array or nil
|
@@ -965,7 +965,7 @@ rb_ary_aref(int argc, VALUE *argv, VALUE ary)
|
|
965
965
|
return rb_ary_entry(ary, NUM2LONG(arg));
|
966
966
|
}
|
967
967
|
|
968
|
-
/*
|
968
|
+
/*
|
969
969
|
* call-seq:
|
970
970
|
* array.at(index) -> obj or nil
|
971
971
|
*
|
@@ -988,11 +988,11 @@ rb_ary_at(VALUE ary, VALUE pos)
|
|
988
988
|
* call-seq:
|
989
989
|
* array.first -> obj or nil
|
990
990
|
* array.first(n) -> an_array
|
991
|
-
*
|
991
|
+
*
|
992
992
|
* Returns the first element, or the first +n+ elements, of the array.
|
993
993
|
* If the array is empty, the first form returns <code>nil</code>, and the
|
994
994
|
* second form returns an empty array.
|
995
|
-
*
|
995
|
+
*
|
996
996
|
* a = [ "q", "r", "s", "t" ]
|
997
997
|
* a.first #=> "q"
|
998
998
|
* a.first(2) #=> ["q", "r"]
|
@@ -1014,10 +1014,10 @@ rb_ary_first(int argc, VALUE *argv, VALUE ary)
|
|
1014
1014
|
* call-seq:
|
1015
1015
|
* array.last -> obj or nil
|
1016
1016
|
* array.last(n) -> an_array
|
1017
|
-
*
|
1017
|
+
*
|
1018
1018
|
* Returns the last element(s) of <i>self</i>. If the array is empty,
|
1019
1019
|
* the first form returns <code>nil</code>.
|
1020
|
-
*
|
1020
|
+
*
|
1021
1021
|
* a = [ "w", "x", "y", "z" ]
|
1022
1022
|
* a.last #=> "z"
|
1023
1023
|
* a.last(2) #=> ["y", "z"]
|
@@ -1040,14 +1040,14 @@ rb_ary_last(int argc, VALUE *argv, VALUE ary)
|
|
1040
1040
|
* array.fetch(index) -> obj
|
1041
1041
|
* array.fetch(index, default ) -> obj
|
1042
1042
|
* array.fetch(index) {|index| block } -> obj
|
1043
|
-
*
|
1043
|
+
*
|
1044
1044
|
* Tries to return the element at position <i>index</i>. If the index
|
1045
1045
|
* lies outside the array, the first form throws an
|
1046
1046
|
* <code>IndexError</code> exception, the second form returns
|
1047
1047
|
* <i>default</i>, and the third form returns the value of invoking
|
1048
1048
|
* the block, passing in the index. Negative values of <i>index</i>
|
1049
1049
|
* count from the end of the array.
|
1050
|
-
*
|
1050
|
+
*
|
1051
1051
|
* a = [ 11, 22, 33, 44 ]
|
1052
1052
|
* a.fetch(1) #=> 22
|
1053
1053
|
* a.fetch(-1) #=> 44
|
@@ -1086,12 +1086,12 @@ rb_ary_fetch(int argc, VALUE *argv, VALUE ary)
|
|
1086
1086
|
* call-seq:
|
1087
1087
|
* array.index(obj) -> int or nil
|
1088
1088
|
* array.index {|item| block} -> int or nil
|
1089
|
-
*
|
1089
|
+
*
|
1090
1090
|
* Returns the index of the first object in <i>self</i> such that is
|
1091
1091
|
* <code>==</code> to <i>obj</i>. If a block is given instead of an
|
1092
1092
|
* argument, returns first object for which <em>block</em> is true.
|
1093
1093
|
* Returns <code>nil</code> if no match is found.
|
1094
|
-
*
|
1094
|
+
*
|
1095
1095
|
* a = [ "a", "b", "c" ]
|
1096
1096
|
* a.index("b") #=> 1
|
1097
1097
|
* a.index("z") #=> nil
|
@@ -1126,12 +1126,12 @@ rb_ary_index(int argc, VALUE *argv, VALUE ary)
|
|
1126
1126
|
/*
|
1127
1127
|
* call-seq:
|
1128
1128
|
* array.rindex(obj) -> int or nil
|
1129
|
-
*
|
1129
|
+
*
|
1130
1130
|
* Returns the index of the last object in <i>array</i>
|
1131
1131
|
* <code>==</code> to <i>obj</i>. If a block is given instead of an
|
1132
1132
|
* argument, returns first object for which <em>block</em> is
|
1133
1133
|
* true. Returns <code>nil</code> if no match is found.
|
1134
|
-
*
|
1134
|
+
*
|
1135
1135
|
* a = [ "a", "b", "b", "b", "c" ]
|
1136
1136
|
* a.rindex("b") #=> 3
|
1137
1137
|
* a.rindex("z") #=> nil
|
@@ -1236,7 +1236,7 @@ rb_ary_splice(VALUE ary, long beg, long len, VALUE rpl)
|
|
1236
1236
|
}
|
1237
1237
|
}
|
1238
1238
|
|
1239
|
-
/*
|
1239
|
+
/*
|
1240
1240
|
* call-seq:
|
1241
1241
|
* array[index] = obj -> obj
|
1242
1242
|
* array[start, length] = obj or an_array or nil -> obj or an_array or nil
|
@@ -1252,7 +1252,7 @@ rb_ary_splice(VALUE ary, long beg, long len, VALUE rpl)
|
|
1252
1252
|
* zero. An +IndexError+ is raised if a negative index points
|
1253
1253
|
* past the beginning of the array. See also
|
1254
1254
|
* <code>Array#push</code>, and <code>Array#unshift</code>.
|
1255
|
-
*
|
1255
|
+
*
|
1256
1256
|
* a = Array.new
|
1257
1257
|
* a[4] = "4"; #=> [nil, nil, nil, nil, "4"]
|
1258
1258
|
* a[0, 3] = [ 'a', 'b', 'c' ] #=> ["a", "b", "c", nil, "4"]
|
@@ -1297,10 +1297,10 @@ fixnum:
|
|
1297
1297
|
/*
|
1298
1298
|
* call-seq:
|
1299
1299
|
* array.insert(index, obj...) -> array
|
1300
|
-
*
|
1300
|
+
*
|
1301
1301
|
* Inserts the given values before the element with the given index
|
1302
1302
|
* (which may be negative).
|
1303
|
-
*
|
1303
|
+
*
|
1304
1304
|
* a = %w{ a b c d }
|
1305
1305
|
* a.insert(2, 99) #=> ["a", "b", 99, "c", "d"]
|
1306
1306
|
* a.insert(-2, 1, 2, 3) #=> ["a", "b", 99, "c", 1, 2, 3, "d"]
|
@@ -1329,15 +1329,15 @@ rb_ary_insert(int argc, VALUE *argv, VALUE ary)
|
|
1329
1329
|
/*
|
1330
1330
|
* call-seq:
|
1331
1331
|
* array.each {|item| block } -> array
|
1332
|
-
*
|
1332
|
+
*
|
1333
1333
|
* Calls <i>block</i> once for each element in <i>self</i>, passing that
|
1334
1334
|
* element as a parameter.
|
1335
|
-
*
|
1335
|
+
*
|
1336
1336
|
* a = [ "a", "b", "c" ]
|
1337
1337
|
* a.each {|x| print x, " -- " }
|
1338
|
-
*
|
1338
|
+
*
|
1339
1339
|
* produces:
|
1340
|
-
*
|
1340
|
+
*
|
1341
1341
|
* a -- b -- c --
|
1342
1342
|
*/
|
1343
1343
|
|
@@ -1356,15 +1356,15 @@ rb_ary_each(VALUE ary)
|
|
1356
1356
|
/*
|
1357
1357
|
* call-seq:
|
1358
1358
|
* array.each_index {|index| block } -> array
|
1359
|
-
*
|
1359
|
+
*
|
1360
1360
|
* Same as <code>Array#each</code>, but passes the index of the element
|
1361
1361
|
* instead of the element itself.
|
1362
|
-
*
|
1362
|
+
*
|
1363
1363
|
* a = [ "a", "b", "c" ]
|
1364
1364
|
* a.each_index {|x| print x, " -- " }
|
1365
|
-
*
|
1365
|
+
*
|
1366
1366
|
* produces:
|
1367
|
-
*
|
1367
|
+
*
|
1368
1368
|
* 0 -- 1 -- 2 --
|
1369
1369
|
*/
|
1370
1370
|
|
@@ -1382,16 +1382,16 @@ rb_ary_each_index(VALUE ary)
|
|
1382
1382
|
|
1383
1383
|
/*
|
1384
1384
|
* call-seq:
|
1385
|
-
* array.reverse_each {|item| block }
|
1386
|
-
*
|
1385
|
+
* array.reverse_each {|item| block }
|
1386
|
+
*
|
1387
1387
|
* Same as <code>Array#each</code>, but traverses <i>self</i> in reverse
|
1388
1388
|
* order.
|
1389
|
-
*
|
1389
|
+
*
|
1390
1390
|
* a = [ "a", "b", "c" ]
|
1391
1391
|
* a.reverse_each {|x| print x, " " }
|
1392
|
-
*
|
1392
|
+
*
|
1393
1393
|
* produces:
|
1394
|
-
*
|
1394
|
+
*
|
1395
1395
|
* c b a
|
1396
1396
|
*/
|
1397
1397
|
|
@@ -1414,9 +1414,9 @@ rb_ary_reverse_each(VALUE ary)
|
|
1414
1414
|
/*
|
1415
1415
|
* call-seq:
|
1416
1416
|
* array.length -> int
|
1417
|
-
*
|
1417
|
+
*
|
1418
1418
|
* Returns the number of elements in <i>self</i>. May be zero.
|
1419
|
-
*
|
1419
|
+
*
|
1420
1420
|
* [ 1, 2, 3, 4, 5 ].length #=> 5
|
1421
1421
|
*/
|
1422
1422
|
|
@@ -1430,9 +1430,9 @@ rb_ary_length(VALUE ary)
|
|
1430
1430
|
/*
|
1431
1431
|
* call-seq:
|
1432
1432
|
* array.empty? -> true or false
|
1433
|
-
*
|
1433
|
+
*
|
1434
1434
|
* Returns <code>true</code> if <i>self</i> array contains no elements.
|
1435
|
-
*
|
1435
|
+
*
|
1436
1436
|
* [].empty? #=> true
|
1437
1437
|
*/
|
1438
1438
|
|
@@ -1525,10 +1525,10 @@ rb_ary_join(VALUE ary, VALUE sep)
|
|
1525
1525
|
/*
|
1526
1526
|
* call-seq:
|
1527
1527
|
* array.join(sep=$,) -> str
|
1528
|
-
*
|
1528
|
+
*
|
1529
1529
|
* Returns a string created by converting each element of the array to
|
1530
1530
|
* a string, separated by <i>sep</i>.
|
1531
|
-
*
|
1531
|
+
*
|
1532
1532
|
* [ "a", "b", "c" ].join #=> "abc"
|
1533
1533
|
* [ "a", "b", "c" ].join("-") #=> "a-b-c"
|
1534
1534
|
*/
|
@@ -1540,7 +1540,7 @@ rb_ary_join_m(int argc, VALUE *argv, VALUE ary)
|
|
1540
1540
|
|
1541
1541
|
rb_scan_args(argc, argv, "01", &sep);
|
1542
1542
|
if (NIL_P(sep)) sep = rb_output_fs;
|
1543
|
-
|
1543
|
+
|
1544
1544
|
return rb_ary_join(ary, sep);
|
1545
1545
|
}
|
1546
1546
|
|
@@ -1591,7 +1591,7 @@ rb_ary_to_s(VALUE ary)
|
|
1591
1591
|
/*
|
1592
1592
|
* call-seq:
|
1593
1593
|
* array.to_a -> array
|
1594
|
-
*
|
1594
|
+
*
|
1595
1595
|
* Returns _self_. If called on a subclass of Array, converts
|
1596
1596
|
* the receiver to an Array object.
|
1597
1597
|
*/
|
@@ -1610,7 +1610,7 @@ rb_ary_to_a(VALUE ary)
|
|
1610
1610
|
/*
|
1611
1611
|
* call-seq:
|
1612
1612
|
* array.to_ary -> array
|
1613
|
-
*
|
1613
|
+
*
|
1614
1614
|
* Returns _self_.
|
1615
1615
|
*/
|
1616
1616
|
|
@@ -1642,10 +1642,10 @@ rb_ary_reverse(VALUE ary)
|
|
1642
1642
|
|
1643
1643
|
/*
|
1644
1644
|
* call-seq:
|
1645
|
-
* array.reverse! -> array
|
1646
|
-
*
|
1645
|
+
* array.reverse! -> array
|
1646
|
+
*
|
1647
1647
|
* Reverses _self_ in place.
|
1648
|
-
*
|
1648
|
+
*
|
1649
1649
|
* a = [ "a", "b", "c" ]
|
1650
1650
|
* a.reverse! #=> ["c", "b", "a"]
|
1651
1651
|
* a #=> ["c", "b", "a"]
|
@@ -1660,9 +1660,9 @@ rb_ary_reverse_bang(VALUE ary)
|
|
1660
1660
|
/*
|
1661
1661
|
* call-seq:
|
1662
1662
|
* array.reverse -> an_array
|
1663
|
-
*
|
1663
|
+
*
|
1664
1664
|
* Returns a new array containing <i>self</i>'s elements in reverse order.
|
1665
|
-
*
|
1665
|
+
*
|
1666
1666
|
* [ "a", "b", "c" ].reverse #=> ["c", "b", "a"]
|
1667
1667
|
* [ 1 ].reverse #=> [1]
|
1668
1668
|
*/
|
@@ -1745,14 +1745,14 @@ sort_2(const void *ap, const void *bp, void *dummy)
|
|
1745
1745
|
/*
|
1746
1746
|
* call-seq:
|
1747
1747
|
* array.sort! -> array
|
1748
|
-
* array.sort! {| a,b | block } -> array
|
1749
|
-
*
|
1748
|
+
* array.sort! {| a,b | block } -> array
|
1749
|
+
*
|
1750
1750
|
* Sorts _self_. Comparisons for
|
1751
1751
|
* the sort will be done using the <code><=></code> operator or using
|
1752
1752
|
* an optional code block. The block implements a comparison between
|
1753
1753
|
* <i>a</i> and <i>b</i>, returning -1, 0, or +1. See also
|
1754
1754
|
* <code>Enumerable#sort_by</code>.
|
1755
|
-
*
|
1755
|
+
*
|
1756
1756
|
* a = [ "d", "a", "e", "c", "b" ]
|
1757
1757
|
* a.sort #=> ["a", "b", "c", "d", "e"]
|
1758
1758
|
* a.sort {|x,y| y <=> x } #=> ["e", "d", "c", "b", "a"]
|
@@ -1805,7 +1805,7 @@ rb_ary_sort_bang(VALUE ary)
|
|
1805
1805
|
ARY_SET_PTR(ary, RARRAY_PTR(tmp));
|
1806
1806
|
ARY_SET_HEAP_LEN(ary, RARRAY_LEN(tmp));
|
1807
1807
|
ARY_SET_CAPA(ary, ARY_CAPA(tmp));
|
1808
|
-
}
|
1808
|
+
}
|
1809
1809
|
/* tmp was lost ownership for the ptr */
|
1810
1810
|
FL_UNSET(tmp, FL_FREEZE);
|
1811
1811
|
FL_SET_EMBED(tmp);
|
@@ -1820,15 +1820,15 @@ rb_ary_sort_bang(VALUE ary)
|
|
1820
1820
|
|
1821
1821
|
/*
|
1822
1822
|
* call-seq:
|
1823
|
-
* array.sort -> an_array
|
1824
|
-
* array.sort {| a,b | block } -> an_array
|
1825
|
-
*
|
1823
|
+
* array.sort -> an_array
|
1824
|
+
* array.sort {| a,b | block } -> an_array
|
1825
|
+
*
|
1826
1826
|
* Returns a new array created by sorting <i>self</i>. Comparisons for
|
1827
1827
|
* the sort will be done using the <code><=></code> operator or using
|
1828
1828
|
* an optional code block. The block implements a comparison between
|
1829
1829
|
* <i>a</i> and <i>b</i>, returning -1, 0, or +1. See also
|
1830
1830
|
* <code>Enumerable#sort_by</code>.
|
1831
|
-
*
|
1831
|
+
*
|
1832
1832
|
* a = [ "d", "a", "e", "c", "b" ]
|
1833
1833
|
* a.sort #=> ["a", "b", "c", "d", "e"]
|
1834
1834
|
* a.sort {|x,y| y <=> x } #=> ["e", "d", "c", "b", "a"]
|
@@ -1847,11 +1847,11 @@ rb_ary_sort(VALUE ary)
|
|
1847
1847
|
* call-seq:
|
1848
1848
|
* array.collect {|item| block } -> an_array
|
1849
1849
|
* array.map {|item| block } -> an_array
|
1850
|
-
*
|
1851
|
-
* Invokes <i>block</i> once for each element of <i>self</i>. Creates a
|
1850
|
+
*
|
1851
|
+
* Invokes <i>block</i> once for each element of <i>self</i>. Creates a
|
1852
1852
|
* new array containing the values returned by the block.
|
1853
1853
|
* See also <code>Enumerable#collect</code>.
|
1854
|
-
*
|
1854
|
+
*
|
1855
1855
|
* a = [ "a", "b", "c", "d" ]
|
1856
1856
|
* a.collect {|x| x + "!" } #=> ["a!", "b!", "c!", "d!"]
|
1857
1857
|
* a #=> ["a", "b", "c", "d"]
|
@@ -1872,7 +1872,7 @@ rb_ary_collect(VALUE ary)
|
|
1872
1872
|
}
|
1873
1873
|
|
1874
1874
|
|
1875
|
-
/*
|
1875
|
+
/*
|
1876
1876
|
* call-seq:
|
1877
1877
|
* array.collect! {|item| block } -> array
|
1878
1878
|
* array.map! {|item| block } -> array
|
@@ -1880,7 +1880,7 @@ rb_ary_collect(VALUE ary)
|
|
1880
1880
|
* Invokes the block once for each element of _self_, replacing the
|
1881
1881
|
* element with the value returned by _block_.
|
1882
1882
|
* See also <code>Enumerable#collect</code>.
|
1883
|
-
*
|
1883
|
+
*
|
1884
1884
|
* a = [ "a", "b", "c", "d" ]
|
1885
1885
|
* a.collect! {|x| x + "!" }
|
1886
1886
|
* a #=> [ "a!", "b!", "c!", "d!" ]
|
@@ -1927,15 +1927,15 @@ rb_get_values_at(VALUE obj, long olen, int argc, VALUE *argv, VALUE (*func) (VAL
|
|
1927
1927
|
return result;
|
1928
1928
|
}
|
1929
1929
|
|
1930
|
-
/*
|
1930
|
+
/*
|
1931
1931
|
* call-seq:
|
1932
1932
|
* array.values_at(selector,... ) -> an_array
|
1933
1933
|
*
|
1934
1934
|
* Returns an array containing the elements in
|
1935
1935
|
* _self_ corresponding to the given selector(s). The selectors
|
1936
|
-
* may be either integer indices or ranges.
|
1936
|
+
* may be either integer indices or ranges.
|
1937
1937
|
* See also <code>Array#select</code>.
|
1938
|
-
*
|
1938
|
+
*
|
1939
1939
|
* a = %w{ a b c d e f }
|
1940
1940
|
* a.values_at(1, 3, 5)
|
1941
1941
|
* a.values_at(1, 3, 5, 7)
|
@@ -1953,11 +1953,11 @@ rb_ary_values_at(int argc, VALUE *argv, VALUE ary)
|
|
1953
1953
|
/*
|
1954
1954
|
* call-seq:
|
1955
1955
|
* array.select {|item| block } -> an_array
|
1956
|
-
*
|
1956
|
+
*
|
1957
1957
|
* Invokes the block passing in successive elements from <i>array</i>,
|
1958
1958
|
* returning an array containing those elements for which the block
|
1959
1959
|
* returns a true value (equivalent to <code>Enumerable#select</code>).
|
1960
|
-
*
|
1960
|
+
*
|
1961
1961
|
* a = %w{ a b c d e f }
|
1962
1962
|
* a.select {|v| v =~ /[aeiou]/} #=> ["a", "e"]
|
1963
1963
|
*/
|
@@ -1980,14 +1980,14 @@ rb_ary_select(VALUE ary)
|
|
1980
1980
|
|
1981
1981
|
/*
|
1982
1982
|
* call-seq:
|
1983
|
-
* array.delete(obj) -> obj or nil
|
1983
|
+
* array.delete(obj) -> obj or nil
|
1984
1984
|
* array.delete(obj) { block } -> obj or nil
|
1985
|
-
*
|
1985
|
+
*
|
1986
1986
|
* Deletes items from <i>self</i> that are equal to <i>obj</i>. If
|
1987
1987
|
* the item is not found, returns <code>nil</code>. If the optional
|
1988
1988
|
* code block is given, returns the result of <i>block</i> if the item
|
1989
1989
|
* is not found.
|
1990
|
-
*
|
1990
|
+
*
|
1991
1991
|
* a = [ "a", "b", "b", "b", "c" ]
|
1992
1992
|
* a.delete("b") #=> "b"
|
1993
1993
|
* a #=> ["a", "c"]
|
@@ -2056,11 +2056,11 @@ rb_ary_delete_at(VALUE ary, long pos)
|
|
2056
2056
|
/*
|
2057
2057
|
* call-seq:
|
2058
2058
|
* array.delete_at(index) -> obj or nil
|
2059
|
-
*
|
2059
|
+
*
|
2060
2060
|
* Deletes the element at the specified index, returning that element,
|
2061
2061
|
* or <code>nil</code> if the index is out of range. See also
|
2062
2062
|
* <code>Array#slice!</code>.
|
2063
|
-
*
|
2063
|
+
*
|
2064
2064
|
* a = %w( ant bat cat dog )
|
2065
2065
|
* a.delete_at(2) #=> "cat"
|
2066
2066
|
* a #=> ["ant", "bat", "dog"]
|
@@ -2077,12 +2077,12 @@ rb_ary_delete_at_m(VALUE ary, VALUE pos)
|
|
2077
2077
|
* call-seq:
|
2078
2078
|
* array.slice!(index) -> obj or nil
|
2079
2079
|
* array.slice!(start, length) -> sub_array or nil
|
2080
|
-
* array.slice!(range) -> sub_array or nil
|
2081
|
-
*
|
2080
|
+
* array.slice!(range) -> sub_array or nil
|
2081
|
+
*
|
2082
2082
|
* Deletes the element(s) given by an index (optionally with a length)
|
2083
2083
|
* or by a range. Returns the deleted object, subarray, or
|
2084
2084
|
* <code>nil</code> if the index is out of range.
|
2085
|
-
*
|
2085
|
+
*
|
2086
2086
|
* a = [ "a", "b", "c" ]
|
2087
2087
|
* a.slice!(1) #=> "b"
|
2088
2088
|
* a #=> ["a", "c"]
|
@@ -2140,7 +2140,7 @@ rb_ary_slice_bang(int argc, VALUE *argv, VALUE ary)
|
|
2140
2140
|
/*
|
2141
2141
|
* call-seq:
|
2142
2142
|
* array.reject! {|item| block } -> array or nil
|
2143
|
-
*
|
2143
|
+
*
|
2144
2144
|
* Equivalent to <code>Array#delete_if</code>, deleting elements from
|
2145
2145
|
* _self_ for which the block evaluates to true, but returns
|
2146
2146
|
* <code>nil</code> if no changes were made. Also see
|
@@ -2172,7 +2172,7 @@ rb_ary_reject_bang(VALUE ary)
|
|
2172
2172
|
/*
|
2173
2173
|
* call-seq:
|
2174
2174
|
* array.reject {|item| block } -> an_array
|
2175
|
-
*
|
2175
|
+
*
|
2176
2176
|
* Returns a new array containing the items in _self_
|
2177
2177
|
* for which the block is not true.
|
2178
2178
|
*/
|
@@ -2189,10 +2189,10 @@ rb_ary_reject(VALUE ary)
|
|
2189
2189
|
/*
|
2190
2190
|
* call-seq:
|
2191
2191
|
* array.delete_if {|item| block } -> array
|
2192
|
-
*
|
2192
|
+
*
|
2193
2193
|
* Deletes every element of <i>self</i> for which <i>block</i> evaluates
|
2194
2194
|
* to <code>true</code>.
|
2195
|
-
*
|
2195
|
+
*
|
2196
2196
|
* a = [ "a", "b", "c" ]
|
2197
2197
|
* a.delete_if {|x| x >= "b" } #=> ["a"]
|
2198
2198
|
*/
|
@@ -2232,7 +2232,7 @@ take_items(VALUE obj, long n)
|
|
2232
2232
|
* call-seq:
|
2233
2233
|
* array.zip(arg, ...) -> an_array
|
2234
2234
|
* array.zip(arg, ...) {| arr | block } -> nil
|
2235
|
-
*
|
2235
|
+
*
|
2236
2236
|
* Converts any arguments to arrays, then merges elements of
|
2237
2237
|
* <i>self</i> with corresponding elements from each argument. This
|
2238
2238
|
* generates a sequence of <code>self.size</code> <em>n</em>-element
|
@@ -2241,7 +2241,7 @@ take_items(VALUE obj, long n)
|
|
2241
2241
|
* <code>nil</code> values are supplied. If a block given, it is
|
2242
2242
|
* invoked for each output array, otherwise an array of arrays is
|
2243
2243
|
* returned.
|
2244
|
-
*
|
2244
|
+
*
|
2245
2245
|
* a = [ 4, 5, 6 ]
|
2246
2246
|
* b = [ 7, 8, 9 ]
|
2247
2247
|
* [1,2,3].zip(a, b) #=> [[1, 4, 7], [2, 5, 8], [3, 6, 9]]
|
@@ -2284,10 +2284,10 @@ rb_ary_zip(int argc, VALUE *argv, VALUE ary)
|
|
2284
2284
|
/*
|
2285
2285
|
* call-seq:
|
2286
2286
|
* array.transpose -> an_array
|
2287
|
-
*
|
2287
|
+
*
|
2288
2288
|
* Assumes that <i>self</i> is an array of arrays and transposes the
|
2289
2289
|
* rows and columns.
|
2290
|
-
*
|
2290
|
+
*
|
2291
2291
|
* a = [[1,2], [3,4], [5,6]]
|
2292
2292
|
* a.transpose #=> [[1, 3, 5], [2, 4, 6]]
|
2293
2293
|
*/
|
@@ -2323,10 +2323,10 @@ rb_ary_transpose(VALUE ary)
|
|
2323
2323
|
/*
|
2324
2324
|
* call-seq:
|
2325
2325
|
* array.replace(other_array) -> array
|
2326
|
-
*
|
2326
|
+
*
|
2327
2327
|
* Replaces the contents of <i>self</i> with the contents of
|
2328
2328
|
* <i>other_array</i>, truncating or expanding if necessary.
|
2329
|
-
*
|
2329
|
+
*
|
2330
2330
|
* a = [ "a", "b", "c", "d", "e" ]
|
2331
2331
|
* a.replace([ "x", "y", "z" ]) #=> ["x", "y", "z"]
|
2332
2332
|
* a #=> ["x", "y", "z"]
|
@@ -2342,7 +2342,7 @@ rb_ary_replace(VALUE copy, VALUE orig)
|
|
2342
2342
|
if (RARRAY_LEN(orig) <= RARRAY_EMBED_LEN_MAX) {
|
2343
2343
|
VALUE *ptr;
|
2344
2344
|
VALUE shared = 0;
|
2345
|
-
|
2345
|
+
|
2346
2346
|
if (ARY_OWNS_HEAP_P(copy)) {
|
2347
2347
|
xfree(RARRAY_PTR(copy));
|
2348
2348
|
}
|
@@ -2373,7 +2373,7 @@ rb_ary_replace(VALUE copy, VALUE orig)
|
|
2373
2373
|
return copy;
|
2374
2374
|
}
|
2375
2375
|
|
2376
|
-
/*
|
2376
|
+
/*
|
2377
2377
|
* call-seq:
|
2378
2378
|
* array.clear -> array
|
2379
2379
|
*
|
@@ -2402,14 +2402,14 @@ rb_ary_clear(VALUE ary)
|
|
2402
2402
|
* array.fill {|index| block } -> array
|
2403
2403
|
* array.fill(start [, length] ) {|index| block } -> array
|
2404
2404
|
* array.fill(range) {|index| block } -> array
|
2405
|
-
*
|
2405
|
+
*
|
2406
2406
|
* The first three forms set the selected elements of <i>self</i> (which
|
2407
2407
|
* may be the entire array) to <i>obj</i>. A <i>start</i> of
|
2408
2408
|
* <code>nil</code> is equivalent to zero. A <i>length</i> of
|
2409
2409
|
* <code>nil</code> is equivalent to <i>self.length</i>. The last three
|
2410
2410
|
* forms fill the array with the value of the block. The block is
|
2411
2411
|
* passed the absolute index of each element to be filled.
|
2412
|
-
*
|
2412
|
+
*
|
2413
2413
|
* a = [ "a", "b", "c", "d" ]
|
2414
2414
|
* a.fill("x") #=> ["x", "x", "x", "x"]
|
2415
2415
|
* a.fill("z", 2, 2) #=> ["x", "x", "z", "z"]
|
@@ -2489,13 +2489,13 @@ rb_ary_fill(int argc, VALUE *argv, VALUE ary)
|
|
2489
2489
|
return ary;
|
2490
2490
|
}
|
2491
2491
|
|
2492
|
-
/*
|
2492
|
+
/*
|
2493
2493
|
* call-seq:
|
2494
2494
|
* array + other_array -> an_array
|
2495
2495
|
*
|
2496
2496
|
* Concatenation---Returns a new array built by concatenating the
|
2497
2497
|
* two arrays together to produce a third array.
|
2498
|
-
*
|
2498
|
+
*
|
2499
2499
|
* [ 1, 2, 3 ] + [ 4, 5 ] #=> [ 1, 2, 3, 4, 5 ]
|
2500
2500
|
*/
|
2501
2501
|
|
@@ -2514,12 +2514,12 @@ rb_ary_plus(VALUE x, VALUE y)
|
|
2514
2514
|
return z;
|
2515
2515
|
}
|
2516
2516
|
|
2517
|
-
/*
|
2517
|
+
/*
|
2518
2518
|
* call-seq:
|
2519
2519
|
* array.concat(other_array) -> array
|
2520
2520
|
*
|
2521
2521
|
* Appends the elements in other_array to _self_.
|
2522
|
-
*
|
2522
|
+
*
|
2523
2523
|
* [ "a", "b" ].concat( ["c", "d"] ) #=> [ "a", "b", "c", "d" ]
|
2524
2524
|
*/
|
2525
2525
|
|
@@ -2535,7 +2535,7 @@ rb_ary_concat(VALUE x, VALUE y)
|
|
2535
2535
|
}
|
2536
2536
|
|
2537
2537
|
|
2538
|
-
/*
|
2538
|
+
/*
|
2539
2539
|
* call-seq:
|
2540
2540
|
* array * int -> an_array
|
2541
2541
|
* array * str -> a_string
|
@@ -2586,7 +2586,7 @@ rb_ary_times(VALUE ary, VALUE times)
|
|
2586
2586
|
return ary2;
|
2587
2587
|
}
|
2588
2588
|
|
2589
|
-
/*
|
2589
|
+
/*
|
2590
2590
|
* call-seq:
|
2591
2591
|
* array.assoc(obj) -> an_array or nil
|
2592
2592
|
*
|
@@ -2624,12 +2624,12 @@ rb_ary_assoc(VALUE ary, VALUE key)
|
|
2624
2624
|
/*
|
2625
2625
|
* call-seq:
|
2626
2626
|
* array.rassoc(obj) -> an_array or nil
|
2627
|
-
*
|
2627
|
+
*
|
2628
2628
|
* Searches through the array whose elements are also arrays. Compares
|
2629
2629
|
* _obj_ with the second element of each contained array using
|
2630
2630
|
* <code>==</code>. Returns the first contained array that matches. See
|
2631
2631
|
* also <code>Array#assoc</code>.
|
2632
|
-
*
|
2632
|
+
*
|
2633
2633
|
* a = [ [ 1, "one"], [2, "two"], [3, "three"], ["ii", "two"] ]
|
2634
2634
|
* a.rassoc("two") #=> [2, "two"]
|
2635
2635
|
* a.rassoc("four") #=> nil
|
@@ -2664,7 +2664,7 @@ recursive_equal(VALUE ary1, VALUE ary2, int recur)
|
|
2664
2664
|
return Qtrue;
|
2665
2665
|
}
|
2666
2666
|
|
2667
|
-
/*
|
2667
|
+
/*
|
2668
2668
|
* call-seq:
|
2669
2669
|
* array == other_array -> bool
|
2670
2670
|
*
|
@@ -2757,11 +2757,11 @@ rb_ary_hash(VALUE ary)
|
|
2757
2757
|
/*
|
2758
2758
|
* call-seq:
|
2759
2759
|
* array.include?(obj) -> true or false
|
2760
|
-
*
|
2760
|
+
*
|
2761
2761
|
* Returns <code>true</code> if the given object is present in
|
2762
2762
|
* <i>self</i> (that is, if any object <code>==</code> <i>anObject</i>),
|
2763
2763
|
* <code>false</code> otherwise.
|
2764
|
-
*
|
2764
|
+
*
|
2765
2765
|
* a = [ "a", "b", "c" ]
|
2766
2766
|
* a.include?("b") #=> true
|
2767
2767
|
* a.include?("z") #=> false
|
@@ -2771,7 +2771,7 @@ VALUE
|
|
2771
2771
|
rb_ary_includes(VALUE ary, VALUE item)
|
2772
2772
|
{
|
2773
2773
|
long i;
|
2774
|
-
|
2774
|
+
|
2775
2775
|
for (i=0; i<RARRAY_LEN(ary); i++) {
|
2776
2776
|
if (rb_equal(RARRAY_PTR(ary)[i], item)) {
|
2777
2777
|
return Qtrue;
|
@@ -2800,7 +2800,7 @@ recursive_cmp(VALUE ary1, VALUE ary2, int recur)
|
|
2800
2800
|
return Qundef;
|
2801
2801
|
}
|
2802
2802
|
|
2803
|
-
/*
|
2803
|
+
/*
|
2804
2804
|
* call-seq:
|
2805
2805
|
* array <=> other_array -> -1, 0, +1
|
2806
2806
|
*
|
@@ -2814,7 +2814,7 @@ recursive_cmp(VALUE ary1, VALUE ary2, int recur)
|
|
2814
2814
|
* ``equal'' according to <code>Array#<=></code> if and only if they have
|
2815
2815
|
* the same length and the value of each element is equal to the
|
2816
2816
|
* value of the corresponding element in the other array.
|
2817
|
-
*
|
2817
|
+
*
|
2818
2818
|
* [ "a", "a", "c" ] <=> [ "a", "b", "c" ] #=> -1
|
2819
2819
|
* [ 1, 2, 3, 4, 5, 6 ] <=> [ 1, 2 ] #=> +1
|
2820
2820
|
*
|
@@ -2853,7 +2853,7 @@ ary_make_hash(VALUE ary1, VALUE ary2)
|
|
2853
2853
|
return hash;
|
2854
2854
|
}
|
2855
2855
|
|
2856
|
-
/*
|
2856
|
+
/*
|
2857
2857
|
* call-seq:
|
2858
2858
|
* array - other_array -> an_array
|
2859
2859
|
*
|
@@ -2882,7 +2882,7 @@ rb_ary_diff(VALUE ary1, VALUE ary2)
|
|
2882
2882
|
return ary3;
|
2883
2883
|
}
|
2884
2884
|
|
2885
|
-
/*
|
2885
|
+
/*
|
2886
2886
|
* call-seq:
|
2887
2887
|
* array & other_array
|
2888
2888
|
*
|
@@ -2917,7 +2917,7 @@ rb_ary_and(VALUE ary1, VALUE ary2)
|
|
2917
2917
|
return ary3;
|
2918
2918
|
}
|
2919
2919
|
|
2920
|
-
/*
|
2920
|
+
/*
|
2921
2921
|
* call-seq:
|
2922
2922
|
* array | other_array -> an_array
|
2923
2923
|
*
|
@@ -2957,11 +2957,11 @@ rb_ary_or(VALUE ary1, VALUE ary2)
|
|
2957
2957
|
/*
|
2958
2958
|
* call-seq:
|
2959
2959
|
* array.uniq! -> array or nil
|
2960
|
-
*
|
2960
|
+
*
|
2961
2961
|
* Removes duplicate elements from _self_.
|
2962
2962
|
* Returns <code>nil</code> if no changes are made (that is, no
|
2963
2963
|
* duplicates are found).
|
2964
|
-
*
|
2964
|
+
*
|
2965
2965
|
* a = [ "a", "a", "b", "b", "c" ]
|
2966
2966
|
* a.uniq! #=> ["a", "b", "c"]
|
2967
2967
|
* b = [ "a", "b", "c" ]
|
@@ -2993,9 +2993,9 @@ rb_ary_uniq_bang(VALUE ary)
|
|
2993
2993
|
/*
|
2994
2994
|
* call-seq:
|
2995
2995
|
* array.uniq -> an_array
|
2996
|
-
*
|
2996
|
+
*
|
2997
2997
|
* Returns a new array by removing duplicate values in <i>self</i>.
|
2998
|
-
*
|
2998
|
+
*
|
2999
2999
|
* a = [ "a", "a", "b", "b", "c" ]
|
3000
3000
|
* a.uniq #=> ["a", "b", "c"]
|
3001
3001
|
*/
|
@@ -3008,7 +3008,7 @@ rb_ary_uniq(VALUE ary)
|
|
3008
3008
|
return ary;
|
3009
3009
|
}
|
3010
3010
|
|
3011
|
-
/*
|
3011
|
+
/*
|
3012
3012
|
* call-seq:
|
3013
3013
|
* array.compact! -> array or nil
|
3014
3014
|
*
|
@@ -3028,7 +3028,7 @@ rb_ary_compact_bang(VALUE ary)
|
|
3028
3028
|
rb_ary_modify(ary);
|
3029
3029
|
p = t = RARRAY_PTR(ary);
|
3030
3030
|
end = p + RARRAY_LEN(ary);
|
3031
|
-
|
3031
|
+
|
3032
3032
|
while (t < end) {
|
3033
3033
|
if (NIL_P(*t)) t++;
|
3034
3034
|
else *p++ = *t++;
|
@@ -3068,7 +3068,7 @@ rb_ary_compact(VALUE ary)
|
|
3068
3068
|
* array.count -> int
|
3069
3069
|
* array.count(obj) -> int
|
3070
3070
|
* array.count { |item| block } -> int
|
3071
|
-
*
|
3071
|
+
*
|
3072
3072
|
* Returns the number of elements. If an argument is given, counts
|
3073
3073
|
* the number of elements which equals to <i>obj</i>. If a block is
|
3074
3074
|
* given, counts the number of elements yielding a true value.
|
@@ -3168,12 +3168,12 @@ flatten(VALUE ary, int level, int *modified)
|
|
3168
3168
|
* call-seq:
|
3169
3169
|
* array.flatten! -> array or nil
|
3170
3170
|
* array.flatten!(level) -> array or nil
|
3171
|
-
*
|
3171
|
+
*
|
3172
3172
|
* Flattens _self_ in place.
|
3173
3173
|
* Returns <code>nil</code> if no modifications were made (i.e.,
|
3174
3174
|
* <i>array</i> contains no subarrays.) If the optional <i>level</i>
|
3175
3175
|
* argument determines the level of recursion to flatten.
|
3176
|
-
*
|
3176
|
+
*
|
3177
3177
|
* a = [ 1, 2, [3, [4, 5] ] ]
|
3178
3178
|
* a.flatten! #=> [1, 2, 3, 4, 5]
|
3179
3179
|
* a.flatten! #=> nil
|
@@ -3203,12 +3203,12 @@ rb_ary_flatten_bang(int argc, VALUE *argv, VALUE ary)
|
|
3203
3203
|
* call-seq:
|
3204
3204
|
* array.flatten -> an_array
|
3205
3205
|
* array.flatten(level) -> an_array
|
3206
|
-
*
|
3206
|
+
*
|
3207
3207
|
* Returns a new array that is a one-dimensional flattening of this
|
3208
3208
|
* array (recursively). That is, for every element that is an array,
|
3209
3209
|
* extract its elements into the new array. If the optional
|
3210
3210
|
* <i>level</i> argument determines the level of recursion to flatten.
|
3211
|
-
*
|
3211
|
+
*
|
3212
3212
|
* s = [ 1, 2, 3 ] #=> [1, 2, 3]
|
3213
3213
|
* t = [ 4, 5, 6, [7, 8] ] #=> [4, 5, 6, [7, 8]]
|
3214
3214
|
* a = [ s, t, 9, 10 ] #=> [[1, 2, 3], [4, 5, 6, [7, 8]], 9, 10]
|
@@ -3236,7 +3236,7 @@ rb_ary_flatten(int argc, VALUE *argv, VALUE ary)
|
|
3236
3236
|
/*
|
3237
3237
|
* call-seq:
|
3238
3238
|
* array.shuffle! -> array
|
3239
|
-
*
|
3239
|
+
*
|
3240
3240
|
* Shuffles elements in _self_ in place.
|
3241
3241
|
*/
|
3242
3242
|
|
@@ -3260,9 +3260,9 @@ rb_ary_shuffle_bang(VALUE ary)
|
|
3260
3260
|
/*
|
3261
3261
|
* call-seq:
|
3262
3262
|
* array.shuffle -> an_array
|
3263
|
-
*
|
3263
|
+
*
|
3264
3264
|
* Returns a new array with elements of this array shuffled.
|
3265
|
-
*
|
3265
|
+
*
|
3266
3266
|
* a = [ 1, 2, 3 ] #=> [1, 2, 3]
|
3267
3267
|
* a.shuffle #=> [2, 3, 1]
|
3268
3268
|
*/
|
@@ -3280,11 +3280,11 @@ rb_ary_shuffle(VALUE ary)
|
|
3280
3280
|
* call-seq:
|
3281
3281
|
* array.sample -> obj
|
3282
3282
|
* array.sample(n) -> an_array
|
3283
|
-
*
|
3283
|
+
*
|
3284
3284
|
* Choose a random element, or the random +n+ elements, from the array.
|
3285
3285
|
* If the array is empty, the first form returns <code>nil</code>, and the
|
3286
3286
|
* second form returns an empty array.
|
3287
|
-
*
|
3287
|
+
*
|
3288
3288
|
*/
|
3289
3289
|
|
3290
3290
|
|
@@ -3294,7 +3294,7 @@ rb_ary_sample(int argc, VALUE *argv, VALUE ary)
|
|
3294
3294
|
VALUE nv, result, *ptr;
|
3295
3295
|
long n, len, i, j, k, idx[10];
|
3296
3296
|
|
3297
|
-
len = RARRAY_LEN(ary);
|
3297
|
+
len = RARRAY_LEN(ary);
|
3298
3298
|
if (argc == 0) {
|
3299
3299
|
if (len == 0) return Qnil;
|
3300
3300
|
i = len == 1 ? 0 : rb_genrand_real()*len;
|
@@ -3363,16 +3363,16 @@ rb_ary_sample(int argc, VALUE *argv, VALUE ary)
|
|
3363
3363
|
* call-seq:
|
3364
3364
|
* ary.cycle {|obj| block }
|
3365
3365
|
* ary.cycle(n) {|obj| block }
|
3366
|
-
*
|
3366
|
+
*
|
3367
3367
|
* Calls <i>block</i> for each element repeatedly _n_ times or
|
3368
3368
|
* forever if none or nil is given. If a non-positive number is
|
3369
3369
|
* given or the array is empty, does nothing. Returns nil if the
|
3370
3370
|
* loop has finished without getting interrupted.
|
3371
|
-
*
|
3371
|
+
*
|
3372
3372
|
* a = ["a", "b", "c"]
|
3373
3373
|
* a.cycle {|x| puts x } # print, a, b, c, a, b, c,.. forever.
|
3374
3374
|
* a.cycle(2) {|x| puts x } # print, a, b, c, a, b, c.
|
3375
|
-
*
|
3375
|
+
*
|
3376
3376
|
*/
|
3377
3377
|
|
3378
3378
|
static VALUE
|
@@ -3405,9 +3405,9 @@ rb_ary_cycle(int argc, VALUE *argv, VALUE ary)
|
|
3405
3405
|
/*
|
3406
3406
|
* Recursively compute permutations of r elements of the set [0..n-1].
|
3407
3407
|
* When we have a complete permutation of array indexes, copy the values
|
3408
|
-
* at those indexes into a new array and yield that array.
|
3408
|
+
* at those indexes into a new array and yield that array.
|
3409
3409
|
*
|
3410
|
-
* n: the size of the set
|
3410
|
+
* n: the size of the set
|
3411
3411
|
* r: the number of elements in each permutation
|
3412
3412
|
* p: the array (of size r) that we're filling in
|
3413
3413
|
* index: what index we're filling in now
|
@@ -3424,7 +3424,7 @@ permute0(long n, long r, long *p, long index, int *used, VALUE values)
|
|
3424
3424
|
if (index < r-1) { /* if not done yet */
|
3425
3425
|
used[i] = 1; /* mark index used */
|
3426
3426
|
permute0(n, r, p, index+1, /* recurse */
|
3427
|
-
used, values);
|
3427
|
+
used, values);
|
3428
3428
|
used[i] = 0; /* index unused */
|
3429
3429
|
}
|
3430
3430
|
else {
|
@@ -3449,15 +3449,15 @@ permute0(long n, long r, long *p, long index, int *used, VALUE values)
|
|
3449
3449
|
* ary.permutation -> enumerator
|
3450
3450
|
* ary.permutation(n) { |p| block } -> array
|
3451
3451
|
* ary.permutation(n) -> enumerator
|
3452
|
-
*
|
3452
|
+
*
|
3453
3453
|
* When invoked with a block, yield all permutations of length <i>n</i>
|
3454
3454
|
* of the elements of <i>ary</i>, then return the array itself.
|
3455
3455
|
* If <i>n</i> is not specified, yield all permutations of all elements.
|
3456
|
-
* The implementation makes no guarantees about the order in which
|
3456
|
+
* The implementation makes no guarantees about the order in which
|
3457
3457
|
* the permutations are yielded.
|
3458
3458
|
*
|
3459
3459
|
* When invoked without a block, return an enumerator object instead.
|
3460
|
-
*
|
3460
|
+
*
|
3461
3461
|
* Examples:
|
3462
3462
|
*
|
3463
3463
|
* a = [1, 2, 3]
|
@@ -3480,7 +3480,7 @@ rb_ary_permutation(int argc, VALUE *argv, VALUE ary)
|
|
3480
3480
|
rb_scan_args(argc, argv, "01", &num);
|
3481
3481
|
r = NIL_P(num) ? n : NUM2LONG(num); /* Permutation size from argument */
|
3482
3482
|
|
3483
|
-
if (r < 0 || n < r) {
|
3483
|
+
if (r < 0 || n < r) {
|
3484
3484
|
/* no permutations: yield nothing */
|
3485
3485
|
}
|
3486
3486
|
else if (r == 0) { /* exactly one permutation: the zero-length array */
|
@@ -3533,14 +3533,14 @@ combi_len(long n, long k)
|
|
3533
3533
|
* call-seq:
|
3534
3534
|
* ary.combination(n) { |c| block } -> ary
|
3535
3535
|
* ary.combination(n) -> enumerator
|
3536
|
-
*
|
3537
|
-
* When invoked with a block, yields all combinations of length <i>n</i>
|
3536
|
+
*
|
3537
|
+
* When invoked with a block, yields all combinations of length <i>n</i>
|
3538
3538
|
* of elements from <i>ary</i> and then returns <i>ary</i> itself.
|
3539
|
-
* The implementation makes no guarantees about the order in which
|
3539
|
+
* The implementation makes no guarantees about the order in which
|
3540
3540
|
* the combinations are yielded.
|
3541
3541
|
*
|
3542
3542
|
* When invoked without a block, returns an enumerator object instead.
|
3543
|
-
*
|
3543
|
+
*
|
3544
3544
|
* Examples:
|
3545
3545
|
*
|
3546
3546
|
* a = [1, 2, 3, 4]
|
@@ -3550,7 +3550,7 @@ combi_len(long n, long k)
|
|
3550
3550
|
* a.combination(4).to_a #=> [[1,2,3,4]]
|
3551
3551
|
* a.combination(0).to_a #=> [[]] # one combination of length 0
|
3552
3552
|
* a.combination(5).to_a #=> [] # no combinations of length 5
|
3553
|
-
*
|
3553
|
+
*
|
3554
3554
|
*/
|
3555
3555
|
|
3556
3556
|
static VALUE
|
@@ -3600,11 +3600,11 @@ rb_ary_combination(VALUE ary, VALUE num)
|
|
3600
3600
|
/*
|
3601
3601
|
* call-seq:
|
3602
3602
|
* ary.product(other_ary, ...)
|
3603
|
-
*
|
3603
|
+
*
|
3604
3604
|
* Returns an array of all combinations of elements from all arrays.
|
3605
3605
|
* The length of the returned array is the product of the length
|
3606
3606
|
* of ary and the argument arrays
|
3607
|
-
*
|
3607
|
+
*
|
3608
3608
|
* [1,2,3].product([4,5]) # => [[1,4],[1,5],[2,4],[2,5],[3,4],[3,5]]
|
3609
3609
|
* [1,2].product([1,2]) # => [[1,1],[1,2],[2,1],[2,2]]
|
3610
3610
|
* [1,2].product([3,4],[5,6]) # => [[1,3,5],[1,3,6],[1,4,5],[1,4,6],
|
@@ -3631,7 +3631,7 @@ rb_ary_product(int argc, VALUE *argv, VALUE ary)
|
|
3631
3631
|
/* initialize the arrays of arrays */
|
3632
3632
|
arrays[0] = ary;
|
3633
3633
|
for (i = 1; i < n; i++) arrays[i] = to_ary(argv[i-1]);
|
3634
|
-
|
3634
|
+
|
3635
3635
|
/* initialize the counters for the arrays */
|
3636
3636
|
for (i = 0; i < n; i++) counters[i] = 0;
|
3637
3637
|
|
@@ -3677,12 +3677,12 @@ rb_ary_product(int argc, VALUE *argv, VALUE ary)
|
|
3677
3677
|
/*
|
3678
3678
|
* call-seq:
|
3679
3679
|
* ary.take(n) => array
|
3680
|
-
*
|
3680
|
+
*
|
3681
3681
|
* Returns first n elements from <i>ary</i>.
|
3682
|
-
*
|
3682
|
+
*
|
3683
3683
|
* a = [1, 2, 3, 4, 5, 0]
|
3684
3684
|
* a.take(3) # => [1, 2, 3]
|
3685
|
-
*
|
3685
|
+
*
|
3686
3686
|
*/
|
3687
3687
|
|
3688
3688
|
static VALUE
|
@@ -3698,13 +3698,13 @@ rb_ary_take(VALUE obj, VALUE n)
|
|
3698
3698
|
/*
|
3699
3699
|
* call-seq:
|
3700
3700
|
* ary.take_while {|arr| block } => array
|
3701
|
-
*
|
3701
|
+
*
|
3702
3702
|
* Passes elements to the block until the block returns nil or false,
|
3703
3703
|
* then stops iterating and returns an array of all prior elements.
|
3704
|
-
*
|
3704
|
+
*
|
3705
3705
|
* a = [1, 2, 3, 4, 5, 0]
|
3706
3706
|
* a.take_while {|i| i < 3 } # => [1, 2]
|
3707
|
-
*
|
3707
|
+
*
|
3708
3708
|
*/
|
3709
3709
|
|
3710
3710
|
static VALUE
|
@@ -3722,13 +3722,13 @@ rb_ary_take_while(VALUE ary)
|
|
3722
3722
|
/*
|
3723
3723
|
* call-seq:
|
3724
3724
|
* ary.drop(n) => array
|
3725
|
-
*
|
3725
|
+
*
|
3726
3726
|
* Drops first n elements from <i>ary</i>, and returns rest elements
|
3727
3727
|
* in an array.
|
3728
|
-
*
|
3728
|
+
*
|
3729
3729
|
* a = [1, 2, 3, 4, 5, 0]
|
3730
3730
|
* a.drop(3) # => [4, 5, 0]
|
3731
|
-
*
|
3731
|
+
*
|
3732
3732
|
*/
|
3733
3733
|
|
3734
3734
|
static VALUE
|
@@ -3748,14 +3748,14 @@ rb_ary_drop(VALUE ary, VALUE n)
|
|
3748
3748
|
/*
|
3749
3749
|
* call-seq:
|
3750
3750
|
* ary.drop_while {|arr| block } => array
|
3751
|
-
*
|
3751
|
+
*
|
3752
3752
|
* Drops elements up to, but not including, the first element for
|
3753
3753
|
* which the block returns nil or false and returns an array
|
3754
3754
|
* containing the remaining elements.
|
3755
|
-
*
|
3755
|
+
*
|
3756
3756
|
* a = [1, 2, 3, 4, 5, 0]
|
3757
3757
|
* a.drop_while {|i| i < 3 } # => [3, 4, 5, 0]
|
3758
|
-
*
|
3758
|
+
*
|
3759
3759
|
*/
|
3760
3760
|
|
3761
3761
|
static VALUE
|
@@ -3772,11 +3772,11 @@ rb_ary_drop_while(VALUE ary)
|
|
3772
3772
|
|
3773
3773
|
|
3774
3774
|
|
3775
|
-
/* Arrays are ordered, integer-indexed collections of any object.
|
3776
|
-
* Array indexing starts at 0, as in C or Java. A negative index is
|
3777
|
-
* assumed to be relative to the end of the array---that is, an index of -1
|
3778
|
-
* indicates the last element of the array, -2 is the next to last
|
3779
|
-
* element in the array, and so on.
|
3775
|
+
/* Arrays are ordered, integer-indexed collections of any object.
|
3776
|
+
* Array indexing starts at 0, as in C or Java. A negative index is
|
3777
|
+
* assumed to be relative to the end of the array---that is, an index of -1
|
3778
|
+
* indicates the last element of the array, -2 is the next to last
|
3779
|
+
* element in the array, and so on.
|
3780
3780
|
*/
|
3781
3781
|
|
3782
3782
|
void
|