fix_ranges 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/fix_ranges.rb +15 -0
  2. data/spec/spec_fix_ranges.rb +32 -0
  3. metadata +68 -0
data/lib/fix_ranges.rb ADDED
@@ -0,0 +1,15 @@
1
+ class Range
2
+
3
+ def method_missing(method)
4
+ if to_a.respond_to? method
5
+ return to_a.send(method)
6
+ else
7
+ raise NoMethodError
8
+ end
9
+ end
10
+
11
+ end
12
+
13
+ #(1..10).reverse.each {|a| puts a}
14
+ #(1..10).revvvv.each {|a| puts a}
15
+
@@ -0,0 +1,32 @@
1
+
2
+ require 'fix_ranges'
3
+
4
+ describe Range, "Range" do
5
+
6
+ it "try (0..10).each as Normal" do
7
+ test = Array.new
8
+ (0..10).each do |x|
9
+ test << x
10
+ end
11
+ test.should == [0,1,2,3,4,5,6,7,8,9,10]
12
+ end
13
+
14
+
15
+ it "try (0..10).reverse.each" do
16
+ test = Array.new
17
+ (0..10).reverse.each do |x|
18
+ test << x
19
+ end
20
+ test.should == [10,9,8,7,6,5,4,3,2,1,0]
21
+
22
+ end
23
+
24
+ it "try (0..10).reverse_each" do
25
+ test = Array.new
26
+ (0..10).reverse_each do |x|
27
+ test << x
28
+ end
29
+ test.should == [10,9,8,7,6,5,4,3,2,1,0]
30
+ end
31
+
32
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fix_ranges
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Morgan Prior
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-06-29 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: fix_ranges auto converts Range to an Array if the method exists for an array.This allows (0..9).reverse.each and (1..9).reverse_each methods to work directly.
23
+ email: fix_ranges_gem@amaras-tech.co.uk
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - lib/fix_ranges.rb
32
+ - spec/spec_fix_ranges.rb
33
+ has_rdoc: true
34
+ homepage: http://amaras-tech.co.uk/software/fix_ranges
35
+ licenses: []
36
+
37
+ post_install_message:
38
+ rdoc_options: []
39
+
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ hash: 3
48
+ segments:
49
+ - 0
50
+ version: "0"
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ requirements: []
61
+
62
+ rubyforge_project:
63
+ rubygems_version: 1.3.7
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: No longer have to call to_a when using ranges with anything other then .each
67
+ test_files: []
68
+