mynyml-every 0.6 → 0.9
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 +7 -0
- data/Rakefile +10 -1
- data/benchmarks.rb +4 -2
- data/every.gemspec +3 -4
- data/examples.rb +17 -0
- data/lib/every.rb +7 -5
- data/test/test_every.rb +4 -1
- metadata +3 -4
- data/examples/simple.rb +0 -10
data/README
CHANGED
@@ -11,3 +11,10 @@ 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
@@ -1,7 +1,16 @@
|
|
1
|
+
# --------------------------------------------------
|
2
|
+
# tasks mostly copied from thin's Rakefile
|
3
|
+
# http://github.com/macournoyer/thin/tree/master
|
4
|
+
# --------------------------------------------------
|
5
|
+
|
1
6
|
require 'rake/gempackagetask'
|
2
7
|
require 'pathname'
|
3
8
|
require 'yaml'
|
4
9
|
|
10
|
+
RUBY_1_9 = RUBY_VERSION =~ /^1\.9/
|
11
|
+
WIN = (RUBY_PLATFORM =~ /mswin|cygwin/)
|
12
|
+
SUDO = (WIN ? "" : "sudo")
|
13
|
+
|
5
14
|
def gem
|
6
15
|
RUBY_1_9 ? 'gem19' : 'gem'
|
7
16
|
end
|
@@ -12,7 +21,7 @@ end
|
|
12
21
|
|
13
22
|
spec = Gem::Specification.new do |s|
|
14
23
|
s.name = 'every'
|
15
|
-
s.version = '0.
|
24
|
+
s.version = '0.9'
|
16
25
|
s.summary = "Symbol#to_proc's hot cousin. Simple and elegant alternative to using &:method with enumerables."
|
17
26
|
s.description = "Symbol#to_proc's hot cousin. Simple and elegant alternative to using &:method with enumerables."
|
18
27
|
s.author = "Martin Aumont"
|
data/benchmarks.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'pathname'
|
4
4
|
require 'benchmark'
|
5
5
|
root = Pathname(__FILE__).dirname
|
6
|
-
require
|
6
|
+
require root.join('lib/every.rb')
|
7
7
|
|
8
8
|
unless defined?(:a.to_proc)
|
9
9
|
class Symbol
|
@@ -24,7 +24,9 @@ puts
|
|
24
24
|
puts "Two iterations"
|
25
25
|
n = 100_000
|
26
26
|
Benchmark.bm(15) do |bm|
|
27
|
-
bm.report('Block:') { (0..n).map {|i| i.floor
|
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 } }
|
28
29
|
bm.report('Symbol#to_proc:') { (0..n).map(&:floor).map(&:next) }
|
29
30
|
bm.report('every:') { (0..n).every.floor.every.next }
|
31
|
+
bm.report('every (chain):') { (0..n).every { floor.next } }
|
30
32
|
end
|
data/every.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: every
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0.
|
4
|
+
version: "0.9"
|
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-
|
12
|
+
date: 2009-03-22 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -24,8 +24,6 @@ extra_rdoc_files: []
|
|
24
24
|
files:
|
25
25
|
- lib
|
26
26
|
- lib/every.rb
|
27
|
-
- examples
|
28
|
-
- examples/simple.rb
|
29
27
|
- LICENSE
|
30
28
|
- benchmarks.rb
|
31
29
|
- README
|
@@ -34,6 +32,7 @@ files:
|
|
34
32
|
- test
|
35
33
|
- test/test_helper.rb
|
36
34
|
- test/test_every.rb
|
35
|
+
- examples.rb
|
37
36
|
- TODO
|
38
37
|
has_rdoc: true
|
39
38
|
homepage: ""
|
data/examples.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
root = Pathname(__FILE__).dirname.expand_path
|
3
|
+
require root.join('lib/every.rb')
|
4
|
+
|
5
|
+
enum = [1.4, 2.4 ,3.4]
|
6
|
+
puts enum.every.floor.inspect
|
7
|
+
|
8
|
+
enum = %w( axb dxf )
|
9
|
+
puts enum.every.gsub(/x/) { 'y' }.inspect
|
10
|
+
|
11
|
+
enum = %w( foo bar )
|
12
|
+
enum.every.upcase!
|
13
|
+
puts enum.inspect
|
14
|
+
|
15
|
+
enum = %w( foo bar ) << ''
|
16
|
+
puts enum.every.empty?.all?
|
17
|
+
puts enum.every.empty?.any?
|
data/lib/every.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
class Every
|
2
2
|
instance_methods.each { |m| undef_method(m) unless m.match(/^__/) }
|
3
|
-
def initialize(
|
4
|
-
@
|
3
|
+
def initialize(enum)
|
4
|
+
@enum = enum
|
5
5
|
end
|
6
6
|
def method_missing(method, *args, &block)
|
7
|
-
@
|
7
|
+
@enum.map {|o| o.__send__(method, *args, &block) }
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
11
|
module Enumerable
|
12
|
-
def every
|
13
|
-
|
12
|
+
def every(&block)
|
13
|
+
block_given? ?
|
14
|
+
Every.new(self).instance_eval(&block) :
|
15
|
+
Every.new(self)
|
14
16
|
end
|
15
17
|
end
|
data/test/test_every.rb
CHANGED
@@ -10,7 +10,7 @@ class EveryTest < Test::Unit::TestCase
|
|
10
10
|
whitelist = %w( __id__ __send__ method_missing )
|
11
11
|
Every.instance_methods.to_set.should be(whitelist.to_set)
|
12
12
|
end
|
13
|
-
test "
|
13
|
+
test "passes message onto enumerable's items" do
|
14
14
|
[1.4, 2.4, 3.4].every.floor.should be([1,2,3])
|
15
15
|
end
|
16
16
|
test "allows arguments" do
|
@@ -19,5 +19,8 @@ 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
|
22
25
|
end
|
23
26
|
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.
|
4
|
+
version: "0.9"
|
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-
|
12
|
+
date: 2009-03-21 21:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -24,8 +24,6 @@ extra_rdoc_files: []
|
|
24
24
|
files:
|
25
25
|
- lib
|
26
26
|
- lib/every.rb
|
27
|
-
- examples
|
28
|
-
- examples/simple.rb
|
29
27
|
- LICENSE
|
30
28
|
- benchmarks.rb
|
31
29
|
- README
|
@@ -34,6 +32,7 @@ files:
|
|
34
32
|
- test
|
35
33
|
- test/test_helper.rb
|
36
34
|
- test/test_every.rb
|
35
|
+
- examples.rb
|
37
36
|
- TODO
|
38
37
|
has_rdoc: true
|
39
38
|
homepage: ""
|
data/examples/simple.rb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
require 'pathname'
|
2
|
-
root = Pathname(__FILE__).dirname.parent
|
3
|
-
require root.join('lib/every')
|
4
|
-
|
5
|
-
enum = [1.4, 2.4 ,3.4]
|
6
|
-
puts enum.map {|i| i.floor }.inspect
|
7
|
-
puts enum.map(&:floor).inspect
|
8
|
-
puts enum.every.floor.inspect
|
9
|
-
|
10
|
-
puts %w( axb dxf ).every.gsub(/x/,'y').inspect
|