mynyml-every 0.9 → 1.0

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.
data/README CHANGED
@@ -11,10 +11,3 @@ arguments? sure:
11
11
 
12
12
  %w( axb dxf ).every.gsub(/x/,'y') #=> ['ayb', 'dyf']
13
13
  %w( axb dxf ).every.gsub(/x/) { 'y' } #=> ['ayb', 'dyf']
14
-
15
- need to call multiple methods? there's a shortcut:
16
-
17
- enum.every.floor.every.next.every + 2 #=> [4,5,6]
18
- enum.every { floor.next + 2 } #=> [4,5,6]
19
-
20
- like #map, but right to the point.
data/Rakefile CHANGED
@@ -21,7 +21,7 @@ end
21
21
 
22
22
  spec = Gem::Specification.new do |s|
23
23
  s.name = 'every'
24
- s.version = '0.9'
24
+ s.version = '1.0'
25
25
  s.summary = "Symbol#to_proc's hot cousin. Simple and elegant alternative to using &:method with enumerables."
26
26
  s.description = "Symbol#to_proc's hot cousin. Simple and elegant alternative to using &:method with enumerables."
27
27
  s.author = "Martin Aumont"
@@ -4,7 +4,7 @@ require 'pathname'
4
4
  require 'benchmark'
5
5
  root = Pathname(__FILE__).dirname
6
6
  require root.join('lib/every.rb')
7
-
7
+
8
8
  unless defined?(:a.to_proc)
9
9
  class Symbol
10
10
  def to_proc() proc { |obj| obj.__send__(self) } end
@@ -12,21 +12,21 @@ unless defined?(:a.to_proc)
12
12
  end
13
13
 
14
14
  puts
15
- puts "One iteration"
15
+ puts "One call"
16
16
  n = 100_000
17
- Benchmark.bm(15) do |bm|
18
- bm.report('Block:') { (0..n).map {|i| i.floor } }
17
+ Benchmark.bmbm(15) do |bm|
18
+ bm.report('#map:') { (0..n).map {|i| i.floor } }
19
19
  bm.report('Symbol#to_proc:') { (0..n).map(&:floor) }
20
- bm.report('every:') { (0..n).every.floor }
20
+ bm.report('#every:') { (0..n).every.floor }
21
21
  end
22
22
 
23
23
  puts
24
- puts "Two iterations"
24
+ puts "Two calls"
25
25
  n = 100_000
26
- Benchmark.bm(15) do |bm|
27
- bm.report('Block:') { (0..n).map {|i| i.floor.next } }
28
- bm.report('Block2:') { (0..n).map {|i| i.floor }.map {|i| i.next } }
26
+ Benchmark.bmbm(15) do |bm|
27
+ bm.report('#map:') { (0..n).map {|i| i.floor.next } }
28
+ bm.report('#map (x2):') { (0..n).map {|i| i.floor }.map {|i| i.next } }
29
29
  bm.report('Symbol#to_proc:') { (0..n).map(&:floor).map(&:next) }
30
- bm.report('every:') { (0..n).every.floor.every.next }
31
- bm.report('every (chain):') { (0..n).every { floor.next } }
30
+ bm.report('#every:') { (0..n).every.floor.every.next }
31
+ bm.report('#every (chain):') { (0..n).every { floor.next } }
32
32
  end
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: every
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.9"
4
+ version: "1.0"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Aumont
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-22 00:00:00 -04:00
12
+ date: 2009-05-19 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -22,20 +22,22 @@ extensions: []
22
22
  extra_rdoc_files: []
23
23
 
24
24
  files:
25
- - lib
26
- - lib/every.rb
27
- - LICENSE
28
- - benchmarks.rb
29
- - README
30
- - every.gemspec
31
25
  - Rakefile
32
26
  - test
33
- - test/test_helper.rb
34
27
  - test/test_every.rb
35
- - examples.rb
28
+ - test/test_helper.rb
29
+ - every.gemspec
30
+ - benchmarks.rb
36
31
  - TODO
32
+ - lib
33
+ - lib/every.rb
34
+ - LICENSE
35
+ - examples.rb
36
+ - README
37
37
  has_rdoc: true
38
38
  homepage: ""
39
+ licenses: []
40
+
39
41
  post_install_message:
40
42
  rdoc_options: []
41
43
 
@@ -56,9 +58,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
58
  requirements: []
57
59
 
58
60
  rubyforge_project:
59
- rubygems_version: 1.3.1
61
+ rubygems_version: 1.3.3
60
62
  signing_key:
61
- specification_version: 2
63
+ specification_version: 3
62
64
  summary: Symbol#to_proc's hot cousin. Simple and elegant alternative to using &:method with enumerables.
63
65
  test_files: []
64
66
 
@@ -1,17 +1,29 @@
1
- require 'pathname'
2
- root = Pathname(__FILE__).dirname.expand_path
3
- require root.join('lib/every.rb')
1
+ require 'lib/every'
4
2
 
5
3
  enum = [1.4, 2.4 ,3.4]
6
4
  puts enum.every.floor.inspect
5
+ #=> [1, 2, 3]
7
6
 
8
7
  enum = %w( axb dxf )
9
8
  puts enum.every.gsub(/x/) { 'y' }.inspect
9
+ #=> ["ayb", "dyf"]
10
10
 
11
11
  enum = %w( foo bar )
12
12
  enum.every.upcase!
13
13
  puts enum.inspect
14
+ #=> ["FOO", "BAR"]
14
15
 
15
16
  enum = %w( foo bar ) << ''
16
17
  puts enum.every.empty?.all?
18
+ #=> false
17
19
  puts enum.every.empty?.any?
20
+ #=> true
21
+
22
+ enum = [{:name => 'Foo'}, {:name => 'Bar'}]
23
+ puts enum.every[:name].inspect
24
+ #=> ["Foo", "Bar"]
25
+
26
+ enum = [1,2,3]
27
+ puts (enum.every + 1).inspect
28
+ #puts enum.every.+(1).inspect
29
+ #=> [2, 3, 4]
@@ -1,17 +1,17 @@
1
- class Every
2
- instance_methods.each { |m| undef_method(m) unless m.match(/^__/) }
3
- def initialize(enum)
4
- @enum = enum
5
- end
6
- def method_missing(method, *args, &block)
7
- @enum.map {|o| o.__send__(method, *args, &block) }
1
+ module Enumerable
2
+ class Proxy
3
+ instance_methods.each { |m| undef_method(m) unless m.match(/^__/) }
4
+ def initialize(enum, method=:map)
5
+ @enum, @method = enum, method
6
+ end
7
+ def method_missing(method, *args, &block)
8
+ @enum.__send__(@method) {|o| o.__send__(method, *args, &block) }
9
+ end
8
10
  end
9
11
  end
10
12
 
11
13
  module Enumerable
12
- def every(&block)
13
- block_given? ?
14
- Every.new(self).instance_eval(&block) :
15
- Every.new(self)
14
+ def every
15
+ Proxy.new(self)
16
16
  end
17
17
  end
@@ -8,7 +8,7 @@ class EveryTest < Test::Unit::TestCase
8
8
  context "Every" do
9
9
  test "is a basic object" do
10
10
  whitelist = %w( __id__ __send__ method_missing )
11
- Every.instance_methods.to_set.should be(whitelist.to_set)
11
+ Enumerable::Proxy.instance_methods.to_set.should be(whitelist.to_set)
12
12
  end
13
13
  test "passes message onto enumerable's items" do
14
14
  [1.4, 2.4, 3.4].every.floor.should be([1,2,3])
@@ -19,8 +19,5 @@ class EveryTest < Test::Unit::TestCase
19
19
  test "allows blocks" do
20
20
  %w( axb dxf ).every.gsub(/x/) { 'y' }.should be(%w( ayb dyf ))
21
21
  end
22
- test "accepts multi-level message passing" do
23
- [1.4, 2.4, 3.4].every { floor.next + 2 }.should be([4,5,6])
24
- end
25
22
  end
26
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mynyml-every
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.9"
4
+ version: "1.0"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Aumont
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-21 21:00:00 -07:00
12
+ date: 2009-05-18 21:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -22,18 +22,18 @@ extensions: []
22
22
  extra_rdoc_files: []
23
23
 
24
24
  files:
25
- - lib
26
- - lib/every.rb
27
- - LICENSE
28
- - benchmarks.rb
29
- - README
30
- - every.gemspec
31
25
  - Rakefile
32
26
  - test
33
- - test/test_helper.rb
34
27
  - test/test_every.rb
35
- - examples.rb
28
+ - test/test_helper.rb
29
+ - every.gemspec
30
+ - benchmarks.rb
36
31
  - TODO
32
+ - lib
33
+ - lib/every.rb
34
+ - LICENSE
35
+ - examples.rb
36
+ - README
37
37
  has_rdoc: true
38
38
  homepage: ""
39
39
  post_install_message:
@@ -58,7 +58,7 @@ requirements: []
58
58
  rubyforge_project:
59
59
  rubygems_version: 1.2.0
60
60
  signing_key:
61
- specification_version: 2
61
+ specification_version: 3
62
62
  summary: Symbol#to_proc's hot cousin. Simple and elegant alternative to using &:method with enumerables.
63
63
  test_files: []
64
64