facets 2.8.0 → 2.8.1

Sign up to get free protection for your applications and to get access to all the features.
data/AUTHORS CHANGED
@@ -9,6 +9,9 @@
9
9
  The following developers have recently contributed to the development of Facets.
10
10
  They are held in the highest regard for their efforts.
11
11
 
12
+ * Roger Pack Added generational depth to Class#descendants.
13
+ * Marco Otte-Witte Fixed return value of Kernel#extend.
14
+ * Mauro Tortonesi Fixed issues with duration.rb and date.rb.
12
15
  * Sandor Szücs Fixes for String#align_right and #align_left.
13
16
  * Tyler Rick Fixed bug in Time#hence and #ago.
14
17
  * Brian Candler Provided Enumerator::Filter.
@@ -64,6 +67,8 @@ All of their hard work is greatly appreciated.
64
67
  * Jan Molic
65
68
  * George Moschovitis
66
69
  * Michael Neumann
70
+ * Marco Otte-Witte
71
+ * Roger Pack
67
72
  * Tim Pease
68
73
  * Jonas Pfenniger
69
74
  * Ryan Platte
@@ -75,6 +80,7 @@ All of their hard work is greatly appreciated.
75
80
  * Gavin Sinclair
76
81
  * Tilo Sloboda
77
82
  * Phil Tomson
83
+ * Mauro Tortonesi
78
84
  * Peter Vanbroekhoven
79
85
  * Jim Weirich
80
86
  * Jeff Wood
data/MANIFEST CHANGED
@@ -37,6 +37,7 @@ lib/core/facets/class/cattr.rb
37
37
  lib/core/facets/class/cattr_accessor.rb
38
38
  lib/core/facets/class/cattr_reader.rb
39
39
  lib/core/facets/class/cattr_writer.rb
40
+ lib/core/facets/class/descendants.rb
40
41
  lib/core/facets/class/descendents.rb
41
42
  lib/core/facets/class/methodize.rb
42
43
  lib/core/facets/class/pathize.rb
@@ -63,6 +64,7 @@ lib/core/facets/duplicable.rb
63
64
  lib/core/facets/enumerable/accumulate.rb
64
65
  lib/core/facets/enumerable/cluster_by.rb
65
66
  lib/core/facets/enumerable/collect.rb
67
+ lib/core/facets/enumerable/collect_with_index.rb
66
68
  lib/core/facets/enumerable/commonality.rb
67
69
  lib/core/facets/enumerable/compact_map.rb
68
70
  lib/core/facets/enumerable/count.rb
@@ -164,7 +166,6 @@ lib/core/facets/hash.rb
164
166
  lib/core/facets/indexable.rb
165
167
  lib/core/facets/integer/even.rb
166
168
  lib/core/facets/integer/factorial.rb
167
- lib/core/facets/integer/length.rb
168
169
  lib/core/facets/integer/multiple.rb
169
170
  lib/core/facets/integer/odd.rb
170
171
  lib/core/facets/integer/of.rb
@@ -270,7 +271,9 @@ lib/core/facets/nilclass/to_f.rb
270
271
  lib/core/facets/nilclass.rb
271
272
  lib/core/facets/numeric/approx.rb
272
273
  lib/core/facets/numeric/distance.rb
274
+ lib/core/facets/numeric/length.rb
273
275
  lib/core/facets/numeric/round.rb
276
+ lib/core/facets/numeric/size.rb
274
277
  lib/core/facets/numeric.rb
275
278
  lib/core/facets/objectspace/classes.rb
276
279
  lib/core/facets/objectspace/op_fetch.rb
@@ -467,20 +470,20 @@ lib/more/facets/uri.rb
467
470
  lib/more/facets/version.rb
468
471
  lib/more/facets/yaml.rb
469
472
  lib/more/facets/zlib.rb
470
- meta/abstract
471
473
  meta/authors
474
+ meta/collection
472
475
  meta/contact
473
476
  meta/contributors
474
477
  meta/created
478
+ meta/description
475
479
  meta/homepage
476
480
  meta/license
477
481
  meta/loadpath
478
- meta/package
482
+ meta/name
479
483
  meta/released
480
484
  meta/repository
481
485
  meta/sitemap
482
486
  meta/slogan
483
- meta/suite
484
487
  meta/summary
485
488
  meta/version
486
489
  script/conflicts
@@ -519,8 +522,8 @@ test/core/dir/test_multiglob.rb
519
522
  test/core/dir/test_parent.rb
520
523
  test/core/dir/test_recurse.rb
521
524
  test/core/enumerable/test_cluster_by.rb
522
- test/core/enumerable/test_collect.rb
523
525
  test/core/enumerable/test_commonality.rb
526
+ test/core/enumerable/test_compact_map.rb
524
527
  test/core/enumerable/test_count.rb
525
528
  test/core/enumerable/test_defer.rb
526
529
  test/core/enumerable/test_each_by.rb
@@ -531,6 +534,7 @@ test/core/enumerable/test_frequency.rb
531
534
  test/core/enumerable/test_group_by.rb
532
535
  test/core/enumerable/test_inject.rb
533
536
  test/core/enumerable/test_map_detect.rb
537
+ test/core/enumerable/test_map_with_index.rb
534
538
  test/core/enumerable/test_mash.rb
535
539
  test/core/enumerable/test_modulate.rb
536
540
  test/core/enumerable/test_none.rb
@@ -659,6 +663,7 @@ test/core/string/test_divide.rb
659
663
  test/core/string/test_each_char.rb
660
664
  test/core/string/test_each_word.rb
661
665
  test/core/string/test_end_with.rb
666
+ test/core/string/test_expand_tabs.rb
662
667
  test/core/string/test_fold.rb
663
668
  test/core/string/test_indent.rb
664
669
  test/core/string/test_interpolate.rb
@@ -737,7 +742,6 @@ test/more/test_openobject.rb
737
742
  test/more/test_ostruct.rb
738
743
  test/more/test_partial.rb
739
744
  test/more/test_random.rb
740
- test/more/test_recorder.rb
741
745
  test/more/test_shellwords.rb
742
746
  test/more/test_succ.rb
743
747
  test/more/test_thread.rb
@@ -1,5 +1,5 @@
1
- # Generated @ Wed Nov 11 12:32:01 -0500 2009 #:till: ^@ <%= Time.now %>
2
- #:till+377: <%= Dir['facets/**/*.rb'].map{ |f| %[require "#{f}"] }.sort.join("\n") %>
1
+ # Generated @ Fri Dec 25 11:47:16 -0500 2009 #:till: ^@ <%= Time.now %>
2
+ #:till+380: <%= Dir['facets/**/*.rb'].map{ |f| %[require "#{f}"] }.sort.join("\n") %>
3
3
  require "facets/array.rb"
4
4
  require "facets/array/combination.rb"
5
5
  require "facets/array/conjoin.rb"
@@ -37,6 +37,7 @@ require "facets/class/cattr.rb"
37
37
  require "facets/class/cattr_accessor.rb"
38
38
  require "facets/class/cattr_reader.rb"
39
39
  require "facets/class/cattr_writer.rb"
40
+ require "facets/class/descendants.rb"
40
41
  require "facets/class/descendents.rb"
41
42
  require "facets/class/methodize.rb"
42
43
  require "facets/class/pathize.rb"
@@ -63,6 +64,7 @@ require "facets/enumerable.rb"
63
64
  require "facets/enumerable/accumulate.rb"
64
65
  require "facets/enumerable/cluster_by.rb"
65
66
  require "facets/enumerable/collect.rb"
67
+ require "facets/enumerable/collect_with_index.rb"
66
68
  require "facets/enumerable/commonality.rb"
67
69
  require "facets/enumerable/compact_map.rb"
68
70
  require "facets/enumerable/count.rb"
@@ -164,7 +166,6 @@ require "facets/indexable.rb"
164
166
  require "facets/integer.rb"
165
167
  require "facets/integer/even.rb"
166
168
  require "facets/integer/factorial.rb"
167
- require "facets/integer/length.rb"
168
169
  require "facets/integer/multiple.rb"
169
170
  require "facets/integer/odd.rb"
170
171
  require "facets/integer/of.rb"
@@ -270,7 +271,9 @@ require "facets/nilclass/to_f.rb"
270
271
  require "facets/numeric.rb"
271
272
  require "facets/numeric/approx.rb"
272
273
  require "facets/numeric/distance.rb"
274
+ require "facets/numeric/length.rb"
273
275
  require "facets/numeric/round.rb"
276
+ require "facets/numeric/size.rb"
274
277
  require "facets/objectspace.rb"
275
278
  require "facets/objectspace/classes.rb"
276
279
  require "facets/objectspace/op_fetch.rb"
@@ -0,0 +1,48 @@
1
+ class Class
2
+
3
+ # List all descedents of this class.
4
+ #
5
+ # class X ; end
6
+ # class A < X; end
7
+ # class B < X; end
8
+ # X.descendents #=> [A,B]
9
+ #
10
+ # You may also limit the generational distance
11
+ # the subclass may be from the parent class.
12
+ #
13
+ # class X ; end
14
+ # class A < X; end
15
+ # class B < A; end
16
+ # X.descendents #=> [A, B]
17
+ # X.descendents(1) #=> [A]
18
+ #
19
+ # NOTE: This is a intensive operation. Do not
20
+ # expect it to be super fast.
21
+
22
+ def descendants(generations=nil)
23
+ subclass = []
24
+ ObjectSpace.each_object(Class) do |c|
25
+ ancestors = c.ancestors[0..(generations || -1)]
26
+ if ancestors.include?(self) and self != c
27
+ subclass << c
28
+ end
29
+ end
30
+ return subclass
31
+ end
32
+
33
+ #
34
+ alias_method :descendents, :descendants
35
+
36
+ unless defined?(::ActiveSupport)
37
+
38
+ # Obvious alias for descendants.
39
+ #
40
+ # NOTE: ActiveSupport returns string names rather
41
+ # then actual classes, so this is excluded
42
+ # if ActiveSupport has already been loaded.
43
+ alias_method :subclasses, :descendants
44
+
45
+ end
46
+
47
+ end
48
+
@@ -1,34 +1 @@
1
- class Class
2
-
3
- # List all descedents of this class.
4
- #
5
- # class X ; end
6
- # class A < X; end
7
- # class B < X; end
8
- # X.descendents #=> [A,B]
9
- #
10
- # NOTE: This is a intesive operation. Do not
11
- # expect it to be super fast.
12
- def descendents
13
- subclass = []
14
- ObjectSpace.each_object( Class ) do |c|
15
- if c.ancestors.include?( self ) and self != c
16
- subclass << c
17
- end
18
- end
19
- return subclass
20
- end
21
-
22
- unless defined?(::ActiveSupport)
23
-
24
- # Obvious alias for descendents.
25
- #
26
- # NOTE: ActiveSupport returns string names rather
27
- # then actual classes, so this is excluded
28
- # if ActiveSupport has already been loaded.
29
- alias_method :subclasses, :descendents
30
-
31
- end
32
-
33
- end
34
-
1
+ require 'facets/class/descendants'
@@ -3,8 +3,8 @@ require 'facets/enumerator'
3
3
 
4
4
  # = Denumerable
5
5
  #
6
- # Classes which include Enumerable::Filterable will get versions
7
- # of map, select etc. which return a Filter, so that they work
6
+ # Classes which include Denumerable will get versions
7
+ # of map, select etc. which return a Denumerator, so that they work
8
8
  # horizontally without creating intermediate arrays.
9
9
  #
10
10
  module Denumerable
@@ -0,0 +1,2 @@
1
+ require 'facets/enumerable/map_with_index'
2
+
@@ -3,7 +3,7 @@ module Enumerable
3
3
  # A more versitle #compact method. It can be used to
4
4
  # collect and filter items out in one single step.
5
5
  #
6
- # [1,2,3].compact_map do |n|
6
+ # (1..3).compact_map do |n|
7
7
  # n < 1 ? nil : n
8
8
  # end
9
9
  #
@@ -11,8 +11,6 @@ module Enumerable
11
11
  #
12
12
  # [2,3]
13
13
  #
14
- # NOTE: Perhaps nicer to have as added functionality for #compact.
15
- #
16
14
  # CREDIT: Trans
17
15
 
18
16
  def compact_map(trash=nil, &block)
@@ -31,5 +29,6 @@ module Enumerable
31
29
  end
32
30
 
33
31
  alias_method :compact_collect, :compact_map
32
+
34
33
  end
35
34
 
@@ -23,10 +23,6 @@ module Enumerable
23
23
  # take(10).
24
24
  # each { |i| puts i }
25
25
  #
26
- # Using with a block, defer(&b), is equivalent to:
27
- #
28
- # defer.filter(&b)
29
- #
30
26
  # Use a method like to_a or to_h at the end of the chain when you want an
31
27
  # Array or Hash built with the results, or each{...} if you just want
32
28
  # to output each result and discard it.
@@ -5,6 +5,7 @@ module Kernel
5
5
  def extend(*mod, &blk)
6
6
  _extend *mod unless mod.empty?
7
7
  _extend Module.new(&blk) if blk
8
+ self
8
9
  end
9
10
 
10
11
  end
@@ -0,0 +1,10 @@
1
+ class Numeric
2
+
3
+ # Returns +self+.
4
+
5
+ def length
6
+ self
7
+ end
8
+
9
+ end
10
+
@@ -0,0 +1,10 @@
1
+ class Numeric
2
+
3
+ # Returns +self+.
4
+
5
+ def size
6
+ self
7
+ end
8
+
9
+ end
10
+
@@ -4,10 +4,13 @@ class String
4
4
  # then tabs are simply removed. Raises an exception if +n+
5
5
  # is negative.
6
6
  #
7
- # "\t\tHey".expand_tab(2) #=> " Hey"
7
+ # "\t\tHey".expand_tabs(2) #=> " Hey"
8
8
  #
9
9
  # Thanks to GGaramuno for a more efficient algorithm. Very nice.
10
10
  #
11
+ # TODO: Don't much care for the name String#expand_tab.
12
+ # What about a more concise name like #detab?
13
+ #
11
14
  # CREDIT: Gavin Sinclair, Noah Gibbs, GGaramuno
12
15
 
13
16
  def expand_tab(n=8)
@@ -28,8 +31,5 @@ class String
28
31
  # Pluralized form of #expand_tab.
29
32
  alias_method :expand_tabs, :expand_tab
30
33
 
31
- # NOTE: Don't much care for the name String#expand_tab.
32
- # What about a more concise name like #detab?
33
-
34
34
  end
35
35
 
@@ -23,85 +23,3 @@ class String
23
23
 
24
24
  end
25
25
 
26
-
27
- # _____ _
28
- # |_ _|__ ___| |_
29
- # | |/ _ \/ __| __|
30
- # | | __/\__ \ |_
31
- # |_|\___||___/\__|
32
- #
33
- =begin test
34
- require 'test/unit'
35
-
36
- class TC_String_Indent < Test::Unit::TestCase
37
-
38
- def test_positive_indent
39
- assert_equal ' xyz', "xyz". indent(4)
40
- assert_equal ' xyz', " xyz".indent(2)
41
- end
42
-
43
- def test_multi_line_positive_indent
44
- assert_equal " abc\n" +
45
- " xyz" ,
46
- ("abc\n" +
47
- "xyz" ).indent(2)
48
- end
49
-
50
- def test_0_indent
51
- assert_equal 'xyz', 'xyz'.indent(0)
52
- end
53
-
54
- def test_negative_indent
55
- assert_equal ' xyz', ' xyz'.indent(-2)
56
- assert_equal 'xyz', ' xyz'. indent(-2)
57
- end
58
-
59
- def test_multi_line_negative_indent
60
- assert_equal " abc\n" +
61
- " xyz" ,
62
- (" abc\n" +
63
- " xyz" ).indent(-2)
64
- end
65
-
66
- def test_outdent_is_alias_for_negative_indent
67
- assert_equal 'xyz', ' xyz'.outdent(2)
68
- end
69
-
70
- def test_negative_indent_more_than_is_possible
71
- assert_equal 'xyz', ' xyz'.indent(-3)
72
- end
73
-
74
- #-----------------------------------
75
- # Using a character other than space
76
-
77
- def test_nonspace_positive__indent
78
- assert_equal '----xyz', "xyz".indent(4, '-')
79
- end
80
-
81
- def test_nonspace_0_indent
82
- assert_equal 'xyz', 'xyz'.indent(0, '-')
83
- end
84
-
85
- def test_nonspace_negative_indent_nonmatching_character
86
- assert_equal ' xyz', ' xyz'.indent(-2, '-')
87
- assert_equal ' xyz', ' xyz'. indent(-2, '-')
88
- end
89
-
90
- def test_nonspace_negative_indent
91
- assert_equal '--xyz', '----xyz'.indent(-2, '-')
92
- assert_equal 'xyz', '--xyz'.indent(-2, '-')
93
- end
94
-
95
- def test_special_regexp_characters_are_escaped
96
- # make sure . is treated as a literal '.' and not an "any character" wildcard
97
- assert_equal ' xyz', ' xyz'.indent(-2, '.')
98
- assert_equal 'xyz', '..xyz'.indent(-2, '.')
99
-
100
- assert_equal ' xyz', ' xyz'.indent(-2, '^')
101
- assert_equal 'xyz', '^^xyz'.indent(-2, '^')
102
-
103
- assert_equal ' xyz', ' xyz'.indent(-2, '*')
104
- assert_equal 'xyz', '**xyz'.indent(-2, '*')
105
- end
106
- end
107
- =end
@@ -1,7 +1,4 @@
1
1
  require 'facets/string/tabto'
2
- require 'facets/string/margin'
3
- require 'facets/string/indent'
4
- require 'facets/string/expand_tab'
5
2
 
6
3
  class String
7
4
 
@@ -13,7 +10,7 @@ class String
13
10
  gsub(/^ */, ' ' * n)
14
11
  end
15
12
 
16
- # LOG: Deprecated #taballto which was an alias for #tab.
13
+ # NOTE: Deprecated #taballto which was an alias for #tab.
17
14
  #alias_method :taballto, :tab
18
15
 
19
16
  end
@@ -208,7 +208,7 @@ class DateTime
208
208
  # self will just be returned unaltered, since there's no clean way
209
209
  # to map it to a Time
210
210
  def to_time
211
- self.offset == 0 ? ::Time.utc_time(year, month, day, hour, min, sec) : self
211
+ self.offset == 0 ? ::Time.utc(year, month, day, hour, min, sec) : self
212
212
  end
213
213
 
214
214
  # To be able to keep Times, Dates and DateTimes interchangeable on conversions
@@ -128,7 +128,7 @@ class Duration
128
128
  self.class.new(@seconds - other.to_i, segments)
129
129
  end
130
130
 
131
- def +(other)
131
+ def *(other)
132
132
  self.class.new(@seconds * other.to_i, segments)
133
133
  end
134
134
 
@@ -113,14 +113,14 @@ class FileList
113
113
 
114
114
  # List of array methods (that are not in +Object+) that need to be
115
115
  # delegated.
116
- ARRAY_METHODS = (Array.instance_methods - Object.instance_methods).map(&:to_sym)
116
+ ARRAY_METHODS = (Array.instance_methods - Object.instance_methods).map(&:to_s)
117
117
 
118
118
  # List of additional methods that must be delegated.
119
- MUST_DEFINE = %w[to_a inspect].map(&:to_sym)
119
+ MUST_DEFINE = %w[to_a inspect].map(&:to_s)
120
120
 
121
121
  # List of methods that should not be delegated here (we define
122
122
  # special versions of them explicitly below).
123
- MUST_NOT_DEFINE = %w[to_a to_ary partition *].map(&:to_sym)
123
+ MUST_NOT_DEFINE = %w[to_a to_ary partition *].map(&:to_s)
124
124
 
125
125
  # List of delegated methods that return new array values which
126
126
  # need wrapping.
@@ -128,7 +128,7 @@ class FileList
128
128
  map collect sort sort_by select find_all reject grep
129
129
  compact flatten uniq values_at
130
130
  + - & |
131
- ].map(&:to_sym)
131
+ ].map(&:to_s)
132
132
 
133
133
  DELEGATING_METHODS = (ARRAY_METHODS + MUST_DEFINE - MUST_NOT_DEFINE).sort.uniq
134
134
 
@@ -86,59 +86,40 @@ class Pathname
86
86
  self.class.new(File.rootname(to_s))
87
87
  end
88
88
 
89
- # # Already included in 1.8.4+ version of Ruby (except for inclusion flag)
90
- # if not instance_methods.include?(:ascend)
91
- #
92
- # # Calls the _block_ for every successive parent directory of the
93
- # # directory path until the root (absolute path) or +.+ (relative path)
94
- # # is reached.
95
- # def ascend(inclusive=false,&block) # :yield:
96
- # cur_dir = self
97
- # yield( cur_dir.cleanpath ) if inclusive
98
- # until cur_dir.root? or cur_dir == Pathname.new(".")
99
- # cur_dir = cur_dir.parent
100
- # yield cur_dir
101
- # end
102
- # end
103
- #
104
- # end
105
- #
106
- # # Already included in 1.8.4+ version of Ruby
107
- # if ! instance_methods.include?(:descend)
108
- #
109
- # # Calls the _block_ for every successive subdirectory of the
110
- # # directory path from the root (absolute path) until +.+
111
- # # (relative path) is reached.
112
- # def descend()
113
- # @path.scan(%r{[^/]*/?})[0...-1].inject('') do |path, dir|
114
- # yield Pathname.new(path << dir)
115
- # path
116
- # end
117
- # end
118
- #
119
- # end
120
-
121
89
  #
122
90
  def split_root
123
91
  head, tail = *::File.split_root(to_s)
124
92
  [self.class.new(head), self.class.new(tail)]
125
93
  end
126
94
 
127
- #
95
+ # Glob pathnames.
128
96
  def glob(match, *opts)
129
- flags = 0
130
- opts.each do |opt|
131
- case opt when Symbol, String
132
- flags += ::File.const_get("FNM_#{opt}".upcase)
133
- else
134
- flags += opt
135
- end
136
- end
97
+ flags = glob_flags(opts)
137
98
  Dir.glob(::File.join(self.to_s, match), flags).collect{ |m| self.class.new(m) }
138
99
  end
139
100
 
101
+ # Return the first glob match.
140
102
  #
103
+ # DEPRECATE: While slightly faster then glob().first, not really worth it
104
+ # unless this can be rewritten to shortcut on first match (using fnmatch?).
105
+ # In wich case, is there a better name for this method?
141
106
  def glob_first(match, *opts)
107
+ flags = glob_flags(opts)
108
+ file = ::Dir.glob(::File.join(self.to_s, match), flags).first
109
+ file ? self.class.new(file) : nil
110
+ end
111
+
112
+ # Return globbed matches with pathnames relative to the current pathname.
113
+ def glob_relative(match, *opts)
114
+ flags = glob_flags(opts)
115
+ files = Dir.glob(::File.join(self.to_s, match), flags)
116
+ files = files.map{ |f| f.sub(self.to_s.chomp('/') + '/', '') }
117
+ files.collect{ |m| self.class.new(m) }
118
+ end
119
+
120
+ private
121
+
122
+ def glob_flags(opts)
142
123
  flags = 0
143
124
  opts.each do |opt|
144
125
  case opt when Symbol, String
@@ -147,10 +128,11 @@ class Pathname
147
128
  flags += opt
148
129
  end
149
130
  end
150
- file = ::Dir.glob(::File.join(self.to_s, match), flags).first
151
- file ? self.class.new(file) : nil
131
+ flags
152
132
  end
153
133
 
134
+ public
135
+
154
136
  #
155
137
  def empty?
156
138
  Dir.glob(::File.join(self.to_s, '*')).empty?
@@ -166,6 +148,38 @@ class Pathname
166
148
  ::FileUtils.outofdate?(to_s, sources.flatten)
167
149
  end
168
150
 
151
+ # # Already included in 1.8.4+ version of Ruby (except for inclusion flag)
152
+ # if not instance_methods.include?(:ascend)
153
+ #
154
+ # # Calls the _block_ for every successive parent directory of the
155
+ # # directory path until the root (absolute path) or +.+ (relative path)
156
+ # # is reached.
157
+ # def ascend(inclusive=false,&block) # :yield:
158
+ # cur_dir = self
159
+ # yield( cur_dir.cleanpath ) if inclusive
160
+ # until cur_dir.root? or cur_dir == Pathname.new(".")
161
+ # cur_dir = cur_dir.parent
162
+ # yield cur_dir
163
+ # end
164
+ # end
165
+ #
166
+ # end
167
+ #
168
+ # # Already included in 1.8.4+ version of Ruby
169
+ # if ! instance_methods.include?(:descend)
170
+ #
171
+ # # Calls the _block_ for every successive subdirectory of the
172
+ # # directory path from the root (absolute path) until +.+
173
+ # # (relative path) is reached.
174
+ # def descend()
175
+ # @path.scan(%r{[^/]*/?})[0...-1].inject('') do |path, dir|
176
+ # yield Pathname.new(path << dir)
177
+ # path
178
+ # end
179
+ # end
180
+ #
181
+ # end
182
+
169
183
  end
170
184
 
171
185
  class NilClass
File without changes
File without changes
File without changes
@@ -1 +1 @@
1
- 2.8.0
1
+ 2.8.1
@@ -1,6 +1,4 @@
1
- # Test for facets/enumerable/collect
2
-
3
- require 'facets/enumerable/collect.rb'
1
+ require 'facets/enumerable/compact_map.rb'
4
2
  require 'test/unit'
5
3
 
6
4
  class TestEnumerable < Test::Unit::TestCase
@@ -14,16 +12,11 @@ class TestEnumerable < Test::Unit::TestCase
14
12
  # assert_equal( e, a )
15
13
  #end
16
14
 
17
- def test_compact_collect
18
- a = [1,2,nil,4].compact_collect { |e| e }
15
+ def test_compact_map
16
+ a = [1,2,nil,4].compact_map { |e| e }
19
17
  assert_equal( [1,2,4], a )
20
18
  end
21
19
 
22
- def test_collect_with_index
23
- a = [1,2,3].collect_with_index{ |e,i| e*i }
24
- assert_equal( [0,2,6], a )
25
- end
26
-
27
20
  =begin
28
21
  def test_map_send
29
22
  r = [1,2,3].map_send(:+, 1)
@@ -0,0 +1,11 @@
1
+ require 'facets/enumerable/map_with_index.rb'
2
+ require 'test/unit'
3
+
4
+ class TestEnumerable < Test::Unit::TestCase
5
+
6
+ def test_collect_with_index
7
+ a = [1,2,3].collect_with_index{ |e,i| e*i }
8
+ assert_equal( [0,2,6], a )
9
+ end
10
+
11
+ end
@@ -0,0 +1,67 @@
1
+ require 'facets/string/expand_tab'
2
+ require 'test/unit'
3
+
4
+ class TC_String_Expand_Tab < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @tabs = <<-EOF
8
+
9
+ \tOne tab
10
+ \tOne space and one tab
11
+ \t Six spaces, a tab, and a space
12
+ EOF
13
+ end # def setup
14
+
15
+ def test_expand_tabs_1
16
+ expected = <<-EOF
17
+
18
+ One tab
19
+ One space and one tab
20
+ Six spaces, a tab, and a space
21
+ EOF
22
+ assert_equal(expected, @tabs.expand_tabs)
23
+ assert_equal(expected, @tabs.expand_tabs(8))
24
+ end
25
+
26
+ def test_expand_tabs_2
27
+ expected = <<-EOF
28
+
29
+ One tab
30
+ One space and one tab
31
+ Six spaces, a tab, and a space
32
+ EOF
33
+ assert_equal(expected, @tabs.expand_tabs(4))
34
+ end
35
+
36
+ def test_expand_tabs_3
37
+ expected = <<-EOF
38
+
39
+ One tab
40
+ One space and one tab
41
+ Six spaces, a tab, and a space
42
+ EOF
43
+ assert_equal(expected, @tabs.expand_tabs(16))
44
+ end
45
+
46
+ def test_expand_tabs_4
47
+ expected = <<-EOF
48
+
49
+ One tab
50
+ One space and one tab
51
+ Six spaces, a tab, and a space
52
+ EOF
53
+ assert_equal(expected, @tabs.expand_tabs(1))
54
+ end
55
+
56
+ def test_expand_tabs_5
57
+ expected = <<-EOF
58
+
59
+ One tab
60
+ One space and one tab
61
+ Six spaces, a tab, and a space
62
+ EOF
63
+ assert_equal(expected, @tabs.expand_tabs(0))
64
+ end
65
+
66
+ end
67
+
@@ -3,71 +3,11 @@ require 'test/unit'
3
3
 
4
4
  class TC_String_Tab < Test::Unit::TestCase
5
5
 
6
- def setup
7
- @tabs = <<-EOF
8
-
9
- \tOne tab
10
- \tOne space and one tab
11
- \t Six spaces, a tab, and a space
12
- EOF
13
- end # def setup
14
-
15
6
  def test_tab
16
7
  a = "xyz".tab(4)
17
8
  assert_equal( ' ', a[0..3] )
18
9
  # Need to expand on this
19
10
  end
20
11
 
21
- def test_expand_tabs_1
22
- expected = <<-EOF
23
-
24
- One tab
25
- One space and one tab
26
- Six spaces, a tab, and a space
27
- EOF
28
- assert_equal(expected, @tabs.expand_tabs)
29
- assert_equal(expected, @tabs.expand_tabs(8))
30
- end
31
-
32
- def test_expand_tabs_2
33
- expected = <<-EOF
34
-
35
- One tab
36
- One space and one tab
37
- Six spaces, a tab, and a space
38
- EOF
39
- assert_equal(expected, @tabs.expand_tabs(4))
40
- end
41
-
42
- def test_expand_tabs_3
43
- expected = <<-EOF
44
-
45
- One tab
46
- One space and one tab
47
- Six spaces, a tab, and a space
48
- EOF
49
- assert_equal(expected, @tabs.expand_tabs(16))
50
- end
51
-
52
- def test_expand_tabs_4
53
- expected = <<-EOF
54
-
55
- One tab
56
- One space and one tab
57
- Six spaces, a tab, and a space
58
- EOF
59
- assert_equal(expected, @tabs.expand_tabs(1))
60
- end
61
-
62
- def test_expand_tabs_5
63
- expected = <<-EOF
64
-
65
- One tab
66
- One space and one tab
67
- Six spaces, a tab, and a space
68
- EOF
69
- assert_equal(expected, @tabs.expand_tabs(0))
70
- end
71
-
72
12
  end
73
13
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facets
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.0
4
+ version: 2.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Sawyer <transfire@gmail.com>
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-11 00:00:00 -05:00
12
+ date: 2009-12-25 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -79,6 +79,7 @@ files:
79
79
  - lib/core/facets/class/cattr_accessor.rb
80
80
  - lib/core/facets/class/cattr_reader.rb
81
81
  - lib/core/facets/class/cattr_writer.rb
82
+ - lib/core/facets/class/descendants.rb
82
83
  - lib/core/facets/class/descendents.rb
83
84
  - lib/core/facets/class/methodize.rb
84
85
  - lib/core/facets/class/pathize.rb
@@ -105,6 +106,7 @@ files:
105
106
  - lib/core/facets/enumerable/accumulate.rb
106
107
  - lib/core/facets/enumerable/cluster_by.rb
107
108
  - lib/core/facets/enumerable/collect.rb
109
+ - lib/core/facets/enumerable/collect_with_index.rb
108
110
  - lib/core/facets/enumerable/commonality.rb
109
111
  - lib/core/facets/enumerable/compact_map.rb
110
112
  - lib/core/facets/enumerable/count.rb
@@ -206,7 +208,6 @@ files:
206
208
  - lib/core/facets/indexable.rb
207
209
  - lib/core/facets/integer/even.rb
208
210
  - lib/core/facets/integer/factorial.rb
209
- - lib/core/facets/integer/length.rb
210
211
  - lib/core/facets/integer/multiple.rb
211
212
  - lib/core/facets/integer/odd.rb
212
213
  - lib/core/facets/integer/of.rb
@@ -312,7 +313,9 @@ files:
312
313
  - lib/core/facets/nilclass.rb
313
314
  - lib/core/facets/numeric/approx.rb
314
315
  - lib/core/facets/numeric/distance.rb
316
+ - lib/core/facets/numeric/length.rb
315
317
  - lib/core/facets/numeric/round.rb
318
+ - lib/core/facets/numeric/size.rb
316
319
  - lib/core/facets/numeric.rb
317
320
  - lib/core/facets/objectspace/classes.rb
318
321
  - lib/core/facets/objectspace/op_fetch.rb
@@ -509,20 +512,20 @@ files:
509
512
  - lib/more/facets/version.rb
510
513
  - lib/more/facets/yaml.rb
511
514
  - lib/more/facets/zlib.rb
512
- - meta/abstract
513
515
  - meta/authors
516
+ - meta/collection
514
517
  - meta/contact
515
518
  - meta/contributors
516
519
  - meta/created
520
+ - meta/description
517
521
  - meta/homepage
518
522
  - meta/license
519
523
  - meta/loadpath
520
- - meta/package
524
+ - meta/name
521
525
  - meta/released
522
526
  - meta/repository
523
527
  - meta/sitemap
524
528
  - meta/slogan
525
- - meta/suite
526
529
  - meta/summary
527
530
  - meta/version
528
531
  - script/conflicts
@@ -561,8 +564,8 @@ files:
561
564
  - test/core/dir/test_parent.rb
562
565
  - test/core/dir/test_recurse.rb
563
566
  - test/core/enumerable/test_cluster_by.rb
564
- - test/core/enumerable/test_collect.rb
565
567
  - test/core/enumerable/test_commonality.rb
568
+ - test/core/enumerable/test_compact_map.rb
566
569
  - test/core/enumerable/test_count.rb
567
570
  - test/core/enumerable/test_defer.rb
568
571
  - test/core/enumerable/test_each_by.rb
@@ -573,6 +576,7 @@ files:
573
576
  - test/core/enumerable/test_group_by.rb
574
577
  - test/core/enumerable/test_inject.rb
575
578
  - test/core/enumerable/test_map_detect.rb
579
+ - test/core/enumerable/test_map_with_index.rb
576
580
  - test/core/enumerable/test_mash.rb
577
581
  - test/core/enumerable/test_modulate.rb
578
582
  - test/core/enumerable/test_none.rb
@@ -701,6 +705,7 @@ files:
701
705
  - test/core/string/test_each_char.rb
702
706
  - test/core/string/test_each_word.rb
703
707
  - test/core/string/test_end_with.rb
708
+ - test/core/string/test_expand_tabs.rb
704
709
  - test/core/string/test_fold.rb
705
710
  - test/core/string/test_indent.rb
706
711
  - test/core/string/test_interpolate.rb
@@ -779,7 +784,6 @@ files:
779
784
  - test/more/test_ostruct.rb
780
785
  - test/more/test_partial.rb
781
786
  - test/more/test_random.rb
782
- - test/more/test_recorder.rb
783
787
  - test/more/test_shellwords.rb
784
788
  - test/more/test_succ.rb
785
789
  - test/more/test_thread.rb
@@ -860,8 +864,8 @@ test_files:
860
864
  - test/core/dir/test_parent.rb
861
865
  - test/core/dir/test_recurse.rb
862
866
  - test/core/enumerable/test_cluster_by.rb
863
- - test/core/enumerable/test_collect.rb
864
867
  - test/core/enumerable/test_commonality.rb
868
+ - test/core/enumerable/test_compact_map.rb
865
869
  - test/core/enumerable/test_count.rb
866
870
  - test/core/enumerable/test_defer.rb
867
871
  - test/core/enumerable/test_each_by.rb
@@ -872,6 +876,7 @@ test_files:
872
876
  - test/core/enumerable/test_group_by.rb
873
877
  - test/core/enumerable/test_inject.rb
874
878
  - test/core/enumerable/test_map_detect.rb
879
+ - test/core/enumerable/test_map_with_index.rb
875
880
  - test/core/enumerable/test_mash.rb
876
881
  - test/core/enumerable/test_modulate.rb
877
882
  - test/core/enumerable/test_none.rb
@@ -1000,6 +1005,7 @@ test_files:
1000
1005
  - test/core/string/test_each_char.rb
1001
1006
  - test/core/string/test_each_word.rb
1002
1007
  - test/core/string/test_end_with.rb
1008
+ - test/core/string/test_expand_tabs.rb
1003
1009
  - test/core/string/test_fold.rb
1004
1010
  - test/core/string/test_indent.rb
1005
1011
  - test/core/string/test_interpolate.rb
@@ -1078,7 +1084,6 @@ test_files:
1078
1084
  - test/more/test_ostruct.rb
1079
1085
  - test/more/test_partial.rb
1080
1086
  - test/more/test_random.rb
1081
- - test/more/test_recorder.rb
1082
1087
  - test/more/test_shellwords.rb
1083
1088
  - test/more/test_succ.rb
1084
1089
  - test/more/test_thread.rb
@@ -1,16 +0,0 @@
1
- #
2
- # Calculate the number of digits in an integer.
3
- #
4
- # 1.length #=> 1
5
- # 10.length #=> 2
6
- # 100.length #=> 3
7
- #
8
- # CREDIT: Victor H. Goff III
9
-
10
- class Integer
11
- # Returns the length of an integer as an integer.
12
- def length
13
- to_s.length
14
- end
15
- end
16
-
@@ -1,30 +0,0 @@
1
- # Test facets/recorder.rb
2
-
3
- require 'facets/recorder.rb'
4
- require 'test/unit'
5
-
6
- #class Object
7
- # def &(o)
8
- # self && o
9
- # end
10
- #end
11
-
12
- class TCRecorder < Test::Unit::TestCase
13
-
14
- class Z
15
- def name ; 'George' ; end
16
- def age ; 12 ; end
17
- end
18
-
19
- def setup
20
- @z = Z.new
21
- end
22
-
23
- def test_001
24
- r = Recorder.new
25
- q = proc { |x| (x.name == 'George') & (x.age > 10) }
26
- x = q[r]
27
- assert( x.__call__(@z) )
28
- end
29
-
30
- end