supplement 1.6.1 → 1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. data/README +1 -1
  2. data/lib/supplement.c +58 -12
  3. data/lib/supplement.h +2 -2
  4. metadata +9 -5
  5. checksums.yaml +0 -15
data/README CHANGED
@@ -1,4 +1,4 @@
1
- = supplement 1.6.1 -- Useful Ruby enhancements
1
+ = supplement 1.7 -- Useful Ruby enhancements
2
2
 
3
3
  Some simple Ruby extensions.
4
4
 
@@ -53,7 +53,9 @@ static struct supplement_flock *flocks_root = NULL;
53
53
 
54
54
 
55
55
  static VALUE supplement_index_blk( VALUE);
56
+ static VALUE supplement_index_ref( VALUE, VALUE);
56
57
  static VALUE supplement_rindex_blk( VALUE);
58
+ static VALUE supplement_rindex_ref( VALUE, VALUE);
57
59
  #ifdef FEATURE_ARRAY_INDEX_WITH_BLOCK
58
60
  static VALUE supplement_index_val( VALUE, VALUE);
59
61
  static VALUE supplement_rindex_val( VALUE, VALUE);
@@ -899,10 +901,12 @@ rb_ary_indexes( VALUE ary)
899
901
 
900
902
  /*
901
903
  * call-seq:
904
+ * pick( ref) -> obj or nil
902
905
  * pick { |elem| ... } -> obj or nil
903
906
  *
904
- * Deletes the element where the <em>block</em> first returns
905
- * <code>true</code>. Or <code>nil</code> if nothing is found.
907
+ * Deletes the element where first <code>ref === obj</code> is true or the
908
+ * <em>block</em> first returns <code>true</code>. The result will be
909
+ * <code>nil</code> if nothing is found.
906
910
  *
907
911
  * a = %w(ant bat cat dog)
908
912
  * a.pick { |e| e =~ /^c/ } #=> "cat"
@@ -911,16 +915,36 @@ rb_ary_indexes( VALUE ary)
911
915
  */
912
916
 
913
917
  VALUE
914
- rb_ary_pick( VALUE ary)
918
+ rb_ary_pick( int argc, VALUE *argv, VALUE ary)
915
919
  {
920
+ VALUE ref;
916
921
  VALUE pos;
922
+ VALUE p;
923
+
924
+ if (rb_scan_args( argc, argv, "01", &ref) == 1)
925
+ pos = supplement_index_ref( ary, ref);
926
+ else
927
+ pos = supplement_index_blk( ary);
917
928
 
918
- pos = supplement_index_blk( ary);
919
929
  if (!NIL_P( pos))
920
930
  return rb_funcall( ary, id_delete_at, 1, pos);
921
931
  return Qnil;
922
932
  }
923
933
 
934
+ VALUE
935
+ supplement_index_ref( VALUE ary, VALUE ref)
936
+ {
937
+ long i, j;
938
+
939
+ if (!id_eqq)
940
+ id_eqq = rb_intern( "===");
941
+ for (i = 0, j = RARRAY_LEN( ary); j > 0; i++, j--) {
942
+ if (RTEST( rb_funcall( ref, id_eqq, 1, RARRAY_PTR( ary)[ i])))
943
+ return LONG2NUM( i);
944
+ }
945
+ return Qnil;
946
+ }
947
+
924
948
  VALUE
925
949
  supplement_index_blk( VALUE ary)
926
950
  {
@@ -935,11 +959,12 @@ supplement_index_blk( VALUE ary)
935
959
 
936
960
  /*
937
961
  * call-seq:
962
+ * rpick( ref) -> obj or nil
938
963
  * rpick { |elem| ... } -> obj or nil
939
964
  *
940
- * Deletes the element where the <em>block</em> first returns
941
- * <code>true</code>. Or <code>nil</code> if nothing is found. Search
942
- * from right to left.
965
+ * Deletes the element where first <code>ref === obj</code> is true or the
966
+ * <em>block</em> first returns <code>true</code>. The result will be
967
+ * <code>nil</code> if nothing is found. Search from right to left.
943
968
  *
944
969
  * a = %w(ant cow bat cat dog)
945
970
  * a.rpick { |e| e =~ /^c/ } #=> "cat"
@@ -948,16 +973,37 @@ supplement_index_blk( VALUE ary)
948
973
  */
949
974
 
950
975
  VALUE
951
- rb_ary_rpick( VALUE ary)
976
+ rb_ary_rpick( int argc, VALUE *argv, VALUE ary)
952
977
  {
978
+ VALUE ref;
953
979
  VALUE pos;
980
+ VALUE p;
981
+
982
+ if (rb_scan_args( argc, argv, "01", &ref) == 1)
983
+ pos = supplement_rindex_ref( ary, ref);
984
+ else
985
+ pos = supplement_rindex_blk( ary);
954
986
 
955
- pos = supplement_rindex_blk( ary);
956
987
  if (!NIL_P( pos))
957
988
  return rb_funcall( ary, id_delete_at, 1, pos);
958
989
  return Qnil;
959
990
  }
960
991
 
992
+ VALUE
993
+ supplement_rindex_ref( VALUE ary, VALUE ref)
994
+ {
995
+ long i;
996
+
997
+ if (!id_eqq)
998
+ id_eqq = rb_intern( "===");
999
+ for (i = RARRAY_LEN( ary); i;) {
1000
+ --i;
1001
+ if (RTEST( rb_funcall( ref, id_eqq, 1, RARRAY_PTR( ary)[ i])))
1002
+ return LONG2NUM( i);
1003
+ }
1004
+ return Qnil;
1005
+ }
1006
+
961
1007
  VALUE
962
1008
  supplement_rindex_blk( VALUE ary)
963
1009
  {
@@ -965,7 +1011,7 @@ supplement_rindex_blk( VALUE ary)
965
1011
 
966
1012
  for (i = RARRAY_LEN( ary); i;) {
967
1013
  --i;
968
- if (rb_yield( RARRAY_PTR( ary)[ i]))
1014
+ if (RTEST( rb_yield( RARRAY_PTR( ary)[ i])))
969
1015
  return LONG2NUM( i);
970
1016
  }
971
1017
  return Qnil;
@@ -1610,8 +1656,8 @@ void Init_supplement( void)
1610
1656
  rb_define_method( rb_cArray, "notempty?", rb_ary_notempty_p, 0);
1611
1657
  rb_define_method( rb_cArray, "indexes", rb_ary_indexes, 0);
1612
1658
  rb_define_alias( rb_cArray, "keys", "indexes");
1613
- rb_define_method( rb_cArray, "pick", rb_ary_pick, 0);
1614
- rb_define_method( rb_cArray, "rpick", rb_ary_rpick, 0);
1659
+ rb_define_method( rb_cArray, "pick", rb_ary_pick, -1);
1660
+ rb_define_method( rb_cArray, "rpick", rb_ary_rpick, -1);
1615
1661
  #ifdef FEATURE_ARRAY_INDEX_WITH_BLOCK
1616
1662
  rb_define_method( rb_cArray, "index", rb_ary_index, -1);
1617
1663
  rb_define_method( rb_cArray, "rindex", rb_ary_rindex, -1);
@@ -44,8 +44,8 @@ extern VALUE rb_str_axe( int, VALUE *, VALUE);
44
44
 
45
45
  extern VALUE rb_ary_notempty_p( VALUE);
46
46
  extern VALUE rb_ary_indexes( VALUE);
47
- extern VALUE rb_ary_pick( VALUE);
48
- extern VALUE rb_ary_rpick( VALUE);
47
+ extern VALUE rb_ary_pick( int, VALUE *, VALUE);
48
+ extern VALUE rb_ary_rpick( int, VALUE *, VALUE);
49
49
  #ifdef FEATURE_ARRAY_INDEX_WITH_BLOCK
50
50
  extern VALUE rb_ary_index( int, VALUE *, VALUE);
51
51
  extern VALUE rb_ary_rindex( int, VALUE *, VALUE);
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: supplement
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: '1.7'
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Bertram Scharpf
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-10-05 00:00:00.000000000 Z
12
+ date: 2013-11-25 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: autorake
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ! '>='
18
20
  - !ruby/object:Gem::Version
@@ -20,6 +22,7 @@ dependencies:
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ! '>='
25
28
  - !ruby/object:Gem::Version
@@ -53,7 +56,6 @@ files:
53
56
  - LICENSE
54
57
  homepage: http://www.bertram-scharpf.de/software/supplement
55
58
  licenses: []
56
- metadata: {}
57
59
  post_install_message:
58
60
  rdoc_options:
59
61
  - --charset
@@ -63,11 +65,13 @@ rdoc_options:
63
65
  require_paths:
64
66
  - lib
65
67
  required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
66
69
  requirements:
67
70
  - - ! '>='
68
71
  - !ruby/object:Gem::Version
69
72
  version: '0'
70
73
  required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
71
75
  requirements:
72
76
  - - ! '>='
73
77
  - !ruby/object:Gem::Version
@@ -75,8 +79,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
79
  requirements:
76
80
  - Ruby and the autorake gem
77
81
  rubyforge_project: NONE
78
- rubygems_version: 2.0.7
82
+ rubygems_version: 1.8.25
79
83
  signing_key:
80
- specification_version: 4
84
+ specification_version: 3
81
85
  summary: Simple Ruby extensions
82
86
  test_files: []
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MGY0Y2M4OGFjNTc5Zjg1OGVmNTU3NzFlMzhkZDhkNjlhMWQxNGNkMQ==
5
- data.tar.gz: !binary |-
6
- ZjcyODM0M2VjYWI1NWI3MDE0YzBlYzRjZTYxMDc0MzAwMTRkNmQ0Nw==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- Y2ZmZjRlY2MwOTVhMGFlNDlkNjgxZDM5NTRlYzQ5OWU3NTUxNGI3NTA0Y2Zh
10
- MGI1ZWY2MDc5ODU2MTkxMjY5ZjhhYjRmNWU2ZDg4ODM0MzczM2JjYzdiZjA4
11
- YzFiNWM4YWFiNWEwYTY5OWFkY2EzMjhiYTc3NjQwMDY1ZjdjODM=
12
- data.tar.gz: !binary |-
13
- NzQ2ODFjZjQ4MDg4NDU5OWYwYmRjNTJmMjYxMjlkNmY1NTNhNjgzNDVjODc0
14
- YzExNGMzOTg1NjNiZTE0MDRhYWRmZjQ3MzQ2NWI1ZWFjOGQ0NDc3YTNkMzY4
15
- ZjlkYTdhN2M2MWIzNWI2MGE0MmYzYjYyZDc2NzBlMTYxNDE4MGI=