diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-07-03 11:02:53 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-07-03 11:02:53 +0000 |
commit | 9d22a06ea06e9bec5030fd6e2c8481958fcd30d9 (patch) | |
tree | 58b15b4dc85acca1c806388ff3848a3c85fd0ebf /array.c | |
parent | a11ab83884c47f729a8630ab5ef21c7522b48386 (diff) | |
download | ruby-9d22a06ea06e9bec5030fd6e2c8481958fcd30d9.tar.gz |
* array.c (rb_values_at): extract common procedure from
rb_ary_values_at. follow DRY principle.
* re.c (match_values_at): values_at should understand ranges.
* struct.c (rb_struct_values_at): ditto.
* struct.c (inspect_struct): inspect format changed; add "struct "
at the top.
* sprintf.c (rb_f_sprintf): "%p" specifier for inspect output.
(RCR#68)
* eval.c (rb_mod_undef_method): allow "undef_method" to accept
multiple arguments. (RCR#146)
* lib/timeout.rb: put timeout in Timeout module. (RCR#121)
[ruby-talk:61028]
* re.c (match_groups): new method added. (RCR#139)
* variable.c (rb_mod_const_of): should exclude constant defined
in Object, unless retrieving constants of Object.
* string.c (rb_str_new4): do not allocate new string if original
is frozen or already have copy-on-write entry. [ruby-talk:74940]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4031 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r-- | array.c | 54 |
1 files changed, 28 insertions, 26 deletions
@@ -1218,29 +1218,37 @@ rb_ary_collect_bang(ary) return ary; } -static void -push_values_at(result, ary, arg) - VALUE result, ary, arg; +VALUE +rb_values_at(obj, olen, argc, argv, func) + VALUE obj; + long olen; + int argc; + VALUE *argv; + VALUE (*func) _((VALUE,long)); { - long beg, len, i; + VALUE result = rb_ary_new2(argc); + long beg, len, i, j; - if (FIXNUM_P(arg)) { - rb_ary_push(result, rb_ary_entry(ary, FIX2LONG(arg))); - return; - } - /* check if idx is Range */ - switch (rb_range_beg_len(arg, &beg, &len, RARRAY(ary)->len, 0)) { - case Qfalse: - break; - case Qnil: - return; - default: - for (i=0; i<len; i++) { - rb_ary_push(result, rb_ary_entry(ary, i+beg)); + for (i=0; i<argc; i++) { + if (FIXNUM_P(argv[i])) { + rb_ary_push(result, (*func)(obj, FIX2LONG(argv[i]))); + continue; + } + /* check if idx is Range */ + switch (rb_range_beg_len(argv[i], &beg, &len, olen, 0)) { + case Qfalse: + break; + case Qnil: + continue; + default: + for (j=0; j<len; j++) { + rb_ary_push(result, (*func)(obj, j+beg)); + } + continue; } - return; + rb_ary_push(result, (*func)(obj, NUM2LONG(argv[i]))); } - rb_ary_push(result, rb_ary_entry(ary, NUM2LONG(arg))); + return result; } static VALUE @@ -1249,13 +1257,7 @@ rb_ary_values_at(argc, argv, ary) VALUE *argv; VALUE ary; { - VALUE result = rb_ary_new2(argc); - long i; - - for (i=0; i<argc; i++) { - push_values_at(result, ary, argv[i]); - } - return result; + return rb_values_at(ary, RARRAY(ary)->len, argc, argv, rb_ary_entry); } static VALUE |