backports 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/.irbrc +1 -0
  2. data/README.rdoc +55 -3
  3. data/Rakefile +1 -0
  4. data/VERSION.yml +1 -1
  5. data/backports.gemspec +99 -118
  6. data/lib/backports/1.8.7/string.rb +1 -1
  7. data/lib/backports/1.9.1/array.rb +1 -2
  8. data/lib/backports/1.9.1/file.rb +20 -0
  9. data/lib/backports/1.9.1/float.rb +19 -0
  10. data/lib/backports/1.9.1/hash.rb +20 -3
  11. data/lib/backports/1.9.1/integer.rb +19 -0
  12. data/lib/backports/1.9.1/io.rb +18 -3
  13. data/lib/backports/1.9.1/numeric.rb +9 -0
  14. data/lib/backports/1.9.1/regexp.rb +1 -6
  15. data/lib/backports/1.9.1/stdlib/prime.rb +495 -0
  16. data/lib/backports/1.9.1/stdlib.rb +1 -0
  17. data/lib/backports/1.9.1/string.rb +2 -7
  18. data/lib/backports/1.9.2/array.rb +3 -4
  19. data/lib/backports/1.9.2/complex.rb +6 -0
  20. data/lib/backports/1.9.2/stdlib/matrix/eigenvalue_decomposition.rb +886 -0
  21. data/lib/backports/1.9.2/stdlib/matrix/lup_decomposition.rb +218 -0
  22. data/lib/backports/1.9.2/stdlib/matrix.rb +1872 -0
  23. data/lib/backports/1.9.2/stdlib/set.rb +13 -0
  24. data/lib/backports/1.9.2/stdlib.rb +1 -0
  25. data/lib/backports/1.9.3/io.rb +12 -0
  26. data/lib/backports/1.9.3.rb +5 -0
  27. data/lib/backports/1.9.rb +1 -1
  28. data/lib/backports/basic_object.rb +3 -2
  29. data/lib/backports/force/array_map.rb +1 -0
  30. data/lib/backports/force/enumerable_map.rb +3 -0
  31. data/lib/backports/force/hash_select.rb +9 -0
  32. data/lib/backports/force/string_length.rb +10 -0
  33. data/lib/backports/force/string_size.rb +1 -0
  34. data/lib/backports/tools.rb +137 -1
  35. data/test/README +13 -0
  36. metadata +25 -42
  37. data/.gitignore +0 -7
  38. data/test/_README +0 -1
  39. data/test/array_test.rb +0 -82
  40. data/test/basic_object_test.rb +0 -70
  41. data/test/binding_test.rb +0 -20
  42. data/test/enumerable_test.rb +0 -244
  43. data/test/enumerator_test.rb +0 -45
  44. data/test/hash_test.rb +0 -26
  45. data/test/kernel_test.rb +0 -31
  46. data/test/math_test.rb +0 -59
  47. data/test/method_missing_test.rb +0 -37
  48. data/test/method_test.rb +0 -73
  49. data/test/module_test.rb +0 -20
  50. data/test/object_test.rb +0 -35
  51. data/test/proc_test.rb +0 -116
  52. data/test/regexp_test.rb +0 -14
  53. data/test/string_test.rb +0 -74
  54. data/test/symbol_test.rb +0 -23
  55. data/test/test_helper.rb +0 -8
@@ -0,0 +1,13 @@
1
+ class Set
2
+ def delete_if
3
+ block_given? or return enum_for(__method__)
4
+ to_a.each { |o| @hash.delete(o) if yield(o) }
5
+ self
6
+ end unless method_defined? :delete_if
7
+
8
+ def keep_if
9
+ block_given? or return enum_for(__method__)
10
+ to_a.each { |o| @hash.delete(o) unless yield(o) }
11
+ self
12
+ end unless method_defined? :keep_if
13
+ end
@@ -0,0 +1 @@
1
+ Backports::StdLib.extend_relative
@@ -0,0 +1,12 @@
1
+ class << IO
2
+ # Standard in Ruby 1.9.3 See official documentation[http://ruby-doc.org/core-1.9.3/IO.html#method-c-write]
3
+ def write(name, string, offset = nil, options = Backports::Undefined)
4
+ Backports.write(false, name, string, offset, options)
5
+ end unless method_defined? :write
6
+
7
+ # Standard in Ruby 1.9.3 See official documentation[http://ruby-doc.org/core-1.9.3/IO.html#method-c-binwrite]
8
+ # This method does support an options hash, see http://bugs.ruby-lang.org/issues/5782
9
+ def binwrite(name, string, offset = nil, options = Backports::Undefined)
10
+ Backports.write(true, name, string, offset, options)
11
+ end unless method_defined? :binwrite
12
+ end
@@ -0,0 +1,5 @@
1
+ # require this file to load all the backports up to Ruby 1.9.3
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + "/tools")
4
+ Backports.require_relative "1.9.2"
5
+ Backports.require_relative_dir "1.9.3"
data/lib/backports/1.9.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # require this file to load all the backports of Ruby
2
2
 
3
3
  require File.expand_path(File.dirname(__FILE__) + "/tools")
4
- Backports.require_relative "1.9.2"
4
+ Backports.require_relative "1.9.3"
@@ -16,8 +16,9 @@ require File.expand_path(File.dirname(__FILE__) + "/tools")
16
16
  Backports.require_relative '1.8.7'
17
17
 
18
18
  class BasicObject
19
- KEEP = [:instance_eval, :instance_exec, :__send__,
20
- "instance_eval", "instance_exec", "__send__"]
19
+ KEEP = %w[== equal? ! != instance_eval instance_exec __send__]
20
+ KEEP.concat KEEP.map { |e| e.to_sym }
21
+
21
22
  # undefine almost all instance methods
22
23
  begin
23
24
  old_verbose, $VERBOSE = $VERBOSE, nil # silence the warning for undefining __id__
@@ -0,0 +1 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/enumerable_map")
@@ -0,0 +1,3 @@
1
+ Backports.make_block_optional Enumerable, :map, :test_on => 1..2
2
+ Backports.make_block_optional Array, :map, :test_on => [1, 2]
3
+
@@ -0,0 +1,9 @@
1
+ class Hash
2
+ if {}.select{} == []
3
+ def select_with_hash_return
4
+ return to_enum(:select) unless block_given?
5
+ Hash[select_without_hash_return{|k, v| yield [k, v]}]
6
+ end
7
+ Backports.alias_method_chain self, :select, :hash_return
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ class String
4
+ if "é".length > 1 && "é".scan(/./).length == 1
5
+ def length
6
+ unpack("U*").length
7
+ end
8
+ alias_method :size, :length
9
+ end
10
+ end
@@ -0,0 +1 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/string_length")
@@ -21,6 +21,64 @@ module Backports
21
21
  end
22
22
  end
23
23
 
24
+ module StdLib
25
+ class LoadedFeatures
26
+ if RUBY_VERSION >= "1.9"
27
+ # Full paths are recorded in $LOADED_FEATURES.
28
+ def initialize
29
+ # Assume backported features are Ruby libraries (i.e. not C)
30
+ @loaded = $LOADED_FEATURES.group_by{|p| File.basename(p, ".rb")}
31
+ end
32
+
33
+ # Check loaded features for one that matches "#{any of the load path}/#{feature}"
34
+ def include?(feature)
35
+ if fullpaths = @loaded[File.basename(feature, ".rb")]
36
+ fullpaths.any?{|fullpath|
37
+ base_dir, = fullpath.partition("/#{feature}")
38
+ $LOAD_PATH.include?(base_dir)
39
+ }
40
+ end
41
+ end
42
+
43
+ def self.mark_as_loaded(feature)
44
+ # Nothing to do, the full path will be OK
45
+ end
46
+
47
+ else
48
+ # Requested features are recorded in $LOADED_FEATURES
49
+ def include?(feature)
50
+ # Assume backported features are Ruby libraries (i.e. not C)
51
+ $LOADED_FEATURES.include?("#{File.basename(feature, '.rb')}.rb")
52
+ end
53
+
54
+ def self.mark_as_loaded(feature)
55
+ $LOADED_FEATURES << "#{File.basename(feature, '.rb')}.rb"
56
+ end
57
+ end
58
+ end
59
+
60
+ class << self
61
+ attr_accessor :extended_lib
62
+
63
+ def extend_relative relative_dir="stdlib"
64
+ loaded = Backports::StdLib::LoadedFeatures.new
65
+ dir = File.expand_path(relative_dir, File.dirname(caller.first.split(/:\d/,2).first))
66
+ Dir.entries(dir).
67
+ map{|f| Regexp.last_match(1) if /^(.*)\.rb$/ =~ f}.
68
+ compact.
69
+ each do |f|
70
+ path = File.expand_path(f, dir)
71
+ if loaded.include?(f)
72
+ require path
73
+ else
74
+ @extended_lib[f] << path
75
+ end
76
+ end
77
+ end
78
+ end
79
+ self.extended_lib ||= Hash.new{|h, k| h[k] = []}
80
+ end
81
+
24
82
  # Metaprogramming utility to make block optional.
25
83
  # Tests first if block is already optional when given options
26
84
  def self.make_block_optional(mod, *methods)
@@ -32,7 +90,7 @@ module Backports
32
90
  end
33
91
  unless options.empty?
34
92
  test_on = options[:test_on] || self.new
35
- next if (test_on.send(selector, *options.fetch(:arg, [])) rescue false)
93
+ next if (test_on.send(selector, *options.fetch(:arg, []).is_a?(Enumerator)) rescue false)
36
94
  end
37
95
 
38
96
  arity = mod.instance_method(selector).arity
@@ -153,6 +211,14 @@ module Backports
153
211
  coerce_to(obj, Array, :to_ary)
154
212
  end
155
213
 
214
+ def self.try_convert(obj, cls, meth)
215
+ return obj if obj.kind_of?(cls)
216
+ return nil unless obj.respond_to?(meth)
217
+ ret = obj.__send__(meth)
218
+ raise TypeError, "Coercion error: obj.#{meth} did NOT return a #{cls} (was #{ret.class})" unless ret.nil? || ret.kind_of?(cls)
219
+ ret
220
+ end
221
+
156
222
  # Checks for a failed comparison (in which case it throws an ArgumentError)
157
223
  # Additionally, it maps any negative value to -1 and any positive value to +1
158
224
  # (from Rubinius)
@@ -182,4 +248,74 @@ module Backports
182
248
  to.instance_variable_set :@is_lambda, is_lambda
183
249
  to
184
250
  end
251
+
252
+ # Used internally to combine {IO|File} options hash into mode (String or Integer)
253
+ def self.combine_mode_and_option(mode = nil, options = Backports::Undefined)
254
+ # Can't backport autoclose, {internal|external|}encoding
255
+ mode, options = nil, mode if mode.is_a?(Hash) and options == Backports::Undefined
256
+ options = {} if options == Backports::Undefined
257
+ if mode && options[:mode]
258
+ raise ArgumentError, "mode specified twice"
259
+ end
260
+ mode ||= options[:mode] || "r"
261
+ if options[:textmode] || options[:binmode]
262
+ text = options[:textmode] || (mode.is_a?(String) && mode =~ /t/)
263
+ bin = options[:binmode] || (mode.is_a?(String) ? mode =~ /b/ : mode & File::Constants::BINARY != 0)
264
+ if text && bin
265
+ raise ArgumentError, "both textmode and binmode specified"
266
+ end
267
+ case
268
+ when !options[:binmode]
269
+ when mode.is_a?(String)
270
+ mode.insert(1, "b")
271
+ else
272
+ mode |= File::Constants::BINARY
273
+ end
274
+ end
275
+ mode
276
+ end
277
+
278
+ # Used internally to combine {IO|File} options hash into mode (String or Integer) and perm
279
+ def self.combine_mode_perm_and_option(mode = nil, perm = Backports::Undefined, options = Backports::Undefined)
280
+ mode, options = nil, mode if mode.is_a?(Hash) and perm == Backports::Undefined
281
+ perm, options = nil, perm if perm.is_a?(Hash) and options == Backports::Undefined
282
+ perm = nil if perm == Backports::Undefined
283
+ options = {} if options == Backports::Undefined
284
+ if perm && options[:perm]
285
+ raise ArgumentError, "perm specified twice"
286
+ end
287
+ [combine_mode_and_option(mode, options), perm || options[:perm]]
288
+ end
289
+
290
+ def self.write(binary, filename, string, offset, options)
291
+ offset, options = nil, offset if Hash === offset and options == Backports::Undefined
292
+ options = {} if options == Backports::Undefined
293
+ options = {:mode => offset.nil? ? "w" : "r+"}.merge(options)
294
+ args = options[:open_args] || [options]
295
+ File.open(filename, *args) do |f|
296
+ f.binmode if binary && f.respond_to?(:binmode)
297
+ f.seek(offset) unless offset.nil?
298
+ f.write(string)
299
+ end
300
+ end
301
+ end
302
+
303
+ module Kernel
304
+ def require_with_backports(lib)
305
+ begin
306
+ return false unless require_without_backports(lib)
307
+ paths = Backports::StdLib.extended_lib.fetch(lib, nil)
308
+ rescue LoadError
309
+ return false if Backports::StdLib::LoadedFeatures.new.include?(lib)
310
+ raise unless paths = Backports::StdLib.extended_lib.fetch(lib, nil)
311
+ Backports::StdLib::LoadedFeatures.mark_as_loaded(lib)
312
+ end
313
+ if paths
314
+ paths.each do |path|
315
+ require_without_backports(path)
316
+ end
317
+ end
318
+ true
319
+ end
320
+ Backports.alias_method_chain self, :require, :backports
185
321
  end
data/test/README ADDED
@@ -0,0 +1,13 @@
1
+ Backports should be run against RubySpec. Check https://github.com/rubyspec/rubyspec for installation instructions.
2
+
3
+ Use the `--unguarded` option to run all specs, including those of versions higher than the current Ruby. Use the `-r` option to require backports.
4
+
5
+ For example:
6
+
7
+ cd YOUR_PATH_TO/rubyspec
8
+ rvm use 1.8.7
9
+ mspec core/range/cover_spec.rb --unguarded -r YOUR_PATH_TO/backports/lib/backports
10
+
11
+ This will run the specs for Range#cover for Ruby 1.8.7 after loading backports.
12
+
13
+ You need to check which tests fail to decide if it's OK that they do or not. For example it is to be expected that specs checking for encoding behavior will fail, as backports does not support the Ruby 1.9 encoding functionality.
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backports
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
- - 3
8
+ - 4
9
9
  - 0
10
- version: 2.3.0
10
+ version: 2.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Marc-Andr\xC3\xA9 Lafortune"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-23 00:00:00 -04:00
18
+ date: 2012-03-24 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -30,7 +30,7 @@ extra_rdoc_files:
30
30
  - README.rdoc
31
31
  files:
32
32
  - .document
33
- - .gitignore
33
+ - .irbrc
34
34
  - CHANGELOG.rdoc
35
35
  - LICENSE
36
36
  - README.rdoc
@@ -73,18 +73,23 @@ files:
73
73
  - lib/backports/1.9.1/enumerator.rb
74
74
  - lib/backports/1.9.1/env.rb
75
75
  - lib/backports/1.9.1/file.rb
76
+ - lib/backports/1.9.1/float.rb
76
77
  - lib/backports/1.9.1/hash.rb
77
78
  - lib/backports/1.9.1/integer.rb
78
79
  - lib/backports/1.9.1/io.rb
79
80
  - lib/backports/1.9.1/kernel.rb
80
81
  - lib/backports/1.9.1/math.rb
82
+ - lib/backports/1.9.1/numeric.rb
81
83
  - lib/backports/1.9.1/proc.rb
82
84
  - lib/backports/1.9.1/range.rb
83
85
  - lib/backports/1.9.1/regexp.rb
86
+ - lib/backports/1.9.1/stdlib.rb
87
+ - lib/backports/1.9.1/stdlib/prime.rb
84
88
  - lib/backports/1.9.1/string.rb
85
89
  - lib/backports/1.9.1/symbol.rb
86
90
  - lib/backports/1.9.2.rb
87
91
  - lib/backports/1.9.2/array.rb
92
+ - lib/backports/1.9.2/complex.rb
88
93
  - lib/backports/1.9.2/dir.rb
89
94
  - lib/backports/1.9.2/enumerable.rb
90
95
  - lib/backports/1.9.2/float.rb
@@ -96,8 +101,20 @@ files:
96
101
  - lib/backports/1.9.2/random/bits_and_bytes.rb
97
102
  - lib/backports/1.9.2/random/implementation.rb
98
103
  - lib/backports/1.9.2/random/load.rb
104
+ - lib/backports/1.9.2/stdlib.rb
105
+ - lib/backports/1.9.2/stdlib/matrix.rb
106
+ - lib/backports/1.9.2/stdlib/matrix/eigenvalue_decomposition.rb
107
+ - lib/backports/1.9.2/stdlib/matrix/lup_decomposition.rb
108
+ - lib/backports/1.9.2/stdlib/set.rb
109
+ - lib/backports/1.9.3.rb
110
+ - lib/backports/1.9.3/io.rb
99
111
  - lib/backports/1.9.rb
100
112
  - lib/backports/basic_object.rb
113
+ - lib/backports/force/array_map.rb
114
+ - lib/backports/force/enumerable_map.rb
115
+ - lib/backports/force/hash_select.rb
116
+ - lib/backports/force/string_length.rb
117
+ - lib/backports/force/string_size.rb
101
118
  - lib/backports/rails.rb
102
119
  - lib/backports/rails/array.rb
103
120
  - lib/backports/rails/enumerable.rb
@@ -106,31 +123,13 @@ files:
106
123
  - lib/backports/rails/module.rb
107
124
  - lib/backports/rails/string.rb
108
125
  - lib/backports/tools.rb
109
- - test/_README
110
- - test/array_test.rb
111
- - test/basic_object_test.rb
112
- - test/binding_test.rb
113
- - test/enumerable_test.rb
114
- - test/enumerator_test.rb
115
- - test/hash_test.rb
116
- - test/kernel_test.rb
117
- - test/math_test.rb
118
- - test/method_missing_test.rb
119
- - test/method_test.rb
120
- - test/module_test.rb
121
- - test/object_test.rb
122
- - test/proc_test.rb
123
- - test/regexp_test.rb
124
- - test/string_test.rb
125
- - test/symbol_test.rb
126
- - test/test_helper.rb
126
+ - test/README
127
127
  has_rdoc: true
128
128
  homepage: http://github.com/marcandre/backports
129
129
  licenses: []
130
130
 
131
131
  post_install_message:
132
132
  rdoc_options:
133
- - --charset=UTF-8
134
133
  - --title
135
134
  - Backports library
136
135
  - --main
@@ -164,21 +163,5 @@ rubygems_version: 1.3.7
164
163
  signing_key:
165
164
  specification_version: 3
166
165
  summary: Backports of Ruby 1.8.7+ for older ruby.
167
- test_files:
168
- - test/array_test.rb
169
- - test/basic_object_test.rb
170
- - test/binding_test.rb
171
- - test/enumerable_test.rb
172
- - test/enumerator_test.rb
173
- - test/hash_test.rb
174
- - test/kernel_test.rb
175
- - test/math_test.rb
176
- - test/method_missing_test.rb
177
- - test/method_test.rb
178
- - test/module_test.rb
179
- - test/object_test.rb
180
- - test/proc_test.rb
181
- - test/regexp_test.rb
182
- - test/string_test.rb
183
- - test/symbol_test.rb
184
- - test/test_helper.rb
166
+ test_files: []
167
+
data/.gitignore DELETED
@@ -1,7 +0,0 @@
1
- *.sw?
2
- *.rbc
3
- .DS_Store
4
- coverage
5
- rdoc
6
- pkg
7
- assets
data/test/_README DELETED
@@ -1 +0,0 @@
1
- As backports should be ran against RubySpec, tests should ideally be added to RubySpec instead of here...
data/test/array_test.rb DELETED
@@ -1,82 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ArrayTest < Test::Unit::TestCase
4
- context "Array" do
5
- context "#combination" do
6
- should "conform to doc" do
7
- a = [ "a", "b", "c" ]
8
- assert_equal [["a"], ["b"], ["c"]], a.combination(1).to_a
9
- assert_equal [["a", "b"], ["a", "c"], ["b", "c"]], a.combination(2).to_a
10
- assert_equal [["a", "b", "c"]], a.combination(3).to_a
11
- assert_equal [], a.combination(4).to_a
12
- end
13
- end
14
-
15
- context "#flatten" do
16
- should "conform to doc" do
17
- s = [ 1, 2, 3 ]
18
- t = [ 4, 5, 6, [7, 8] ]
19
- a = [ s, t, 9, 10 ]
20
- assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], a.flatten
21
- a = [ 1, 2, [3, [4, 5] ] ]
22
- assert_equal [1, 2, 3, [4, 5]], a.flatten(1)
23
- end
24
- end
25
-
26
- context "#index" do
27
- should "conform to doc" do
28
- a = [ "a", "b", "c" ]
29
- assert_equal 1, a.index("b")
30
- assert_equal nil, a.index("z")
31
- assert_equal 1, a.index{|x|x=="b"}
32
- end
33
- end
34
-
35
- context "#reverse_each" do
36
- should "return an enumerator when no block is given" do
37
- assert_equal [4,3,2], [1,2,3,4].reverse_each.take(3)
38
- end
39
- end
40
-
41
- context "#pop" do
42
- should "conform to doc" do
43
- a = %w{ f r a b j o u s }
44
- assert_equal "s", a.pop
45
- assert_equal ["f", "r", "a", "b", "j", "o", "u"] , a
46
- assert_equal ["j", "o", "u"], a.pop(3)
47
- assert_equal ["f", "r", "a", "b"] , a
48
- end
49
- end
50
-
51
- context "#product" do
52
- should "conform to doc" do
53
- assert_equal [[1, 3], [1, 4], [2, 3], [2, 4]], [1, 2].product([3, 4])
54
- assert_equal [[1, 3, 5], [1, 4, 5], [2, 3, 5], [2, 4, 5]], [1, 2].product([3, 4], [5])
55
- assert_equal [[1], [2]], [1, 2].product
56
- end
57
- end
58
-
59
- context "#sample" do
60
- should "conform to doc" do
61
- assert_equal nil, [].sample
62
- assert_equal [], [].sample(5)
63
- assert_equal 42, [42].sample
64
- assert_equal [42], [42].sample(5)
65
- a = [ :foo, :bar, 42 ]
66
- s = a.sample(2)
67
- assert_equal 2, s.size
68
- assert_equal 1, (a-s).size
69
- assert_equal [], a-(0..20).sum{a.sample(2)}
70
- end
71
- end
72
-
73
- context "#shift" do
74
- should "conform to doc" do
75
- args = [ "-m", "-q", "-v", "filename" ]
76
- assert_equal "-m", args.shift
77
- assert_equal ["-q", "-v"], args.shift(2)
78
- assert_equal ["filename"], args
79
- end
80
- end
81
- end
82
- end
@@ -1,70 +0,0 @@
1
- require 'test_helper'
2
- require 'backports/basic_object'
3
-
4
- class BasicObjectTest < Test::Unit::TestCase
5
- context "BasicObject" do
6
- should "do it's best to keep stuff undefined" do
7
- # written in one big test because sequence matters
8
- # and defining classes / methods can't really be undone
9
-
10
- assert_equal 3, BasicObject.instance_methods.size
11
-
12
- class Subclass < BasicObject
13
- def foo
14
- :bar
15
- end
16
- end
17
-
18
- assert_equal 4, Subclass.instance_methods.size
19
-
20
- module ::Kernel
21
- def bar
22
- :foo
23
- end
24
- end
25
-
26
- assert Subclass.method_defined?(:bar) # for now
27
-
28
- class ForceCleanup < Subclass
29
- end
30
-
31
- assert !Subclass.method_defined?(:bar) # should be cleaned up
32
-
33
- module SomeExtension
34
- def foo
35
- 42
36
- end
37
- end
38
-
39
- class ::Object
40
- include SomeExtension
41
- end
42
-
43
- class ForceCleanupAgain < Subclass
44
- end
45
-
46
- # puts BasicObject.instance_methods - BasicObject.instance_methods(false)
47
- # puts BasicObject.instance_method(:foo).owner
48
- # puts SomeExtension <= Object
49
- assert Subclass.method_defined?(:foo) # should not be cleaned up!
50
- assert !BasicObject.method_defined?(:foo) # but BasicObject should have been cleaned up!
51
-
52
- class BasicObject
53
- def last_case
54
- 1.0/0
55
- end
56
- end
57
-
58
- module SomeExtension
59
- def last_case
60
- 0
61
- end
62
- end
63
-
64
- class ForceCleanupForTheLastTime < BasicObject
65
- end
66
-
67
- assert BasicObject.method_defined?(:last_case)
68
- end
69
- end
70
- end
data/test/binding_test.rb DELETED
@@ -1,20 +0,0 @@
1
- require 'test_helper'
2
-
3
- class BindingTest < Test::Unit::TestCase
4
- class Demo
5
- def initialize(n)
6
- @secret = n
7
- end
8
- def get_binding
9
- return binding()
10
- end
11
- end
12
-
13
- context "Binding" do
14
- context "#eval" do
15
- should "conform to doc" do
16
- assert_equal 99, Demo.new(99).get_binding.eval("@secret")
17
- end
18
- end
19
- end
20
- end