give4each 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,2 +1,4 @@
1
-
2
- * Alpha
1
+ === 0.0.3 / 2012-2-24
2
+ * added Symbol#or
3
+ * added Symbol#and
4
+ * added Symbol#of
data/README.rdoc CHANGED
@@ -9,8 +9,9 @@ https://github.com/pasberth/give4each
9
9
 
10
10
  == description
11
11
 
12
- ああああああ
13
- もうブロックを書くのはうんざりだ!!!
12
+ (1..5).map { |i| i ** 2 } を (1..5).map &:**.with(2) とか書けるようにする
13
+
14
+ == usage
14
15
 
15
16
  (1..5).map { |i| i ** 2 }
16
17
 
data/examples/and.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'gvie4each'
1
+ require 'give4each'
2
2
  # %w[c++ lisp].map do |a|
3
3
  # a.upcase.concat("er")
4
4
  # end
@@ -25,13 +25,9 @@ class Give4Each::MethodChain
25
25
  def method_missing method, *args, &block
26
26
  case method.to_s
27
27
  when /^of_(.*)$/
28
- @current = natural $1, *args, &block
29
- @callings.unshift @current
30
- return self
28
+ return self.of($1, *args, &block)
31
29
  when /^and_(.*)$/
32
- @current = natural $1, *args, &block
33
- @callings.push @current
34
- return self
30
+ return self.and($1, *args, &block)
35
31
  end
36
32
 
37
33
  return to_proc.send method, *args, &block if Proc.instance_methods.include? method
@@ -44,6 +40,56 @@ class Give4Each::MethodChain
44
40
  end
45
41
 
46
42
  private :natural
43
+
44
+ # Wrong :(
45
+ # %w[c++ lisp].map &:upcase.of_+("er")
46
+ # Right :)
47
+ # %w[c++ lisp].map &:upcase.of(:+, "er")
48
+ def of method, *args, &block
49
+ @current = natural method, *args, &block
50
+ @callings.unshift @current
51
+ self
52
+ end
53
+
54
+ # Wrong :( %w[c++ lisp].map &:upcase.of_+("er")
55
+ # Right :) %w[c++ lisp].map &:upcase.of(:+, "er")
56
+ def and method, *args, &block
57
+ @current = natural method, *args, &block
58
+ @callings.push @current
59
+ return self
60
+ end
61
+
62
+ # [
63
+ # [1, 2],
64
+ # [3],
65
+ # []
66
+ # ].map &:first # => [1, 2, nil]
67
+ #
68
+ # I expect the nil is replaced by 0.
69
+ #
70
+ # But this is needlessly long!:
71
+ #
72
+ # [
73
+ # [1, 2],
74
+ # [3],
75
+ # []
76
+ # ].map { |a| a.first or 0 }
77
+ #
78
+ # I think I write:
79
+ #
80
+ # [
81
+ # [1, 2],
82
+ # [3],
83
+ # []
84
+ # ].map &:first.or(0)
85
+ #
86
+ def or default_value
87
+ old = @current.callback
88
+ @current.callback = lambda do |o, has|
89
+ old.call o, has or default_value
90
+ end
91
+ self
92
+ end
47
93
 
48
94
  # example:
49
95
  # # (1..5).map do |i|
@@ -88,7 +134,7 @@ class Give4Each::MethodChain
88
134
  # receiver = "hello %s world"
89
135
  # %w[ruby python].map &:%.in(receiver) # => ["hello ruby world", "hello python world"]
90
136
  # *method chain*:
91
- # %w[ruby python].map &:%.in(receiver).and_upcase # => ["HELLO RUBY WORLD", "HELLO PYTHON WORLD"]
137
+ # %w[ruby python].map &:%.in(receiver).and_upcase # => ["HELLO RUBY WORLD", "HELLO PYTHON WORLD"]
92
138
  # You should not use #to for that.
93
139
  # receiver = "hello %s world"
94
140
  # %w[ruby python].map &:%.to(receiver) # => ["ruby", "python"]
@@ -3,7 +3,7 @@ module Give4Each; end
3
3
  module Give4Each::PrivateHelpers # :nodoc: all
4
4
 
5
5
  def allowing_method? f
6
- [:with, :a, :an, :the, :to, :in].include? f.to_sym or
6
+ [:with, :a, :an, :the, :to, :in, :and, :of, :or].include? f.to_sym or
7
7
  [/^of_.*$/, /^and_.*$/].any?(&:=~.with(f.to_s))
8
8
  end
9
9
 
data/lib/give4each.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  $:.unshift File.dirname(__FILE__)
2
2
 
3
3
  module Give4Each
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.3"
5
5
  end
6
6
 
7
7
  require "give4each/private_helpers"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: give4each
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-19 00:00:00.000000000 Z
12
+ date: 2012-02-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdoc
16
- requirement: &70239049844320 !ruby/object:Gem::Requirement
16
+ requirement: &70353993100060 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.10'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70239049844320
24
+ version_requirements: *70353993100060
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: hoe
27
- requirement: &70239049843680 !ruby/object:Gem::Requirement
27
+ requirement: &70353993099640 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,13 +32,8 @@ dependencies:
32
32
  version: '2.13'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70239049843680
36
- description: ! "ああああああ\nもうブロックを書くのはうんざりだ!!!\n\n (1..5).map { |i| i ** 2 }\n\nだからこう書けるようにした\n
37
- \ \n (1..5).map &:**.with(2) # => [1, 4, 9, 16, 25]\n\nああああああ\nこういうのももう嫌だ!!!\n\n
38
- \ def initialize\n @stack = []\n end\n\n def foo *xs\n xs.each { |x| @stack.push
39
- x }\n end\n\nだからこう書けるように(ry\n\n xs.each &:push.to(@array)\n\n\nこういうのも(ry\n\n
40
- \ f = \"hello %s world\"\n %w[ruby python].map { |a| f % a }\n\nだからこう(ry\n\n %w[ruby
41
- python].map &:%.in(\"hello %s world\")"
35
+ version_requirements: *70353993099640
36
+ description: (1..5).map { |i| i ** 2 } を (1..5).map &:**.with(2) とか書けるようにする
42
37
  email:
43
38
  - pasberth@gmail.com
44
39
  executables: []
@@ -83,9 +78,5 @@ rubyforge_project: give4each
83
78
  rubygems_version: 1.8.10
84
79
  signing_key:
85
80
  specification_version: 3
86
- summary: ! 'ああああああ もうブロックを書くのはうんざりだ!!! (1..5).map { |i| i ** 2 } だからこう書けるようにした (1..5).map
87
- &:**.with(2) # => [1, 4, 9, 16, 25] ああああああ こういうのももう嫌だ!!! def initialize @stack
88
- = [] end def foo *xs xs.each { |x| @stack.push x } end だからこう書けるように(ry xs.each
89
- &:push.to(@array) こういうのも(ry f = "hello %s world" %w[ruby python].map { |a| f
90
- % a } だからこう(ry %w[ruby python].map &:%.in("hello %s world")'
81
+ summary: (1..5).map { |i| i ** 2 }(1..5).map &:**.with(2) とか書けるようにする
91
82
  test_files: []