give4each 0.0.1

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.
File without changes
@@ -0,0 +1,2 @@
1
+
2
+ * Alpha
@@ -0,0 +1,10 @@
1
+
2
+ = Give4each
3
+
4
+ == install
5
+
6
+ $ gem install give4each
7
+
8
+ == example
9
+
10
+ :include: examples/example.rb
@@ -0,0 +1,9 @@
1
+ require './lib/give4each'
2
+ require 'hoe'
3
+
4
+ Hoe.spec 'give4each' do
5
+ self.developer 'pasberth', 'pasberth@gmail.com'
6
+ self.rubyforge_name = self.name
7
+ self.readme_file = 'README.rdoc'
8
+ self.version = Give4Each::VERSION
9
+ end
@@ -0,0 +1,5 @@
1
+ require 'gvie4each'
2
+ # %w[c++ lisp].map do |a|
3
+ # a.upcase.concat("er")
4
+ # end
5
+ %w[c++ lisp].map &:upcase.and_concat.with("er") # => ["C++er", "LISPer"]
@@ -0,0 +1,20 @@
1
+ begin
2
+ require 'give4each'
3
+ rescue LoadError
4
+ require './' + File.dirname(__FILE__) + '/../lib/give4each'
5
+ end
6
+
7
+ # (1..5).map do |i|
8
+ # i ** 2
9
+ # end
10
+ p (1..5).map &:**.with(2) # => [1, 4, 9, 16, 25]
11
+
12
+ # %w[c++ lisp].map do |a|
13
+ # a.concat("er").upcase
14
+ # end
15
+ p %w[c++ lisp].map &:upcase.of_concat.with("er") # => ["C++ER", "LISPER"]
16
+
17
+ # %w[c++ lisp].map do |a|
18
+ # a.upcase.concat("er")
19
+ # end
20
+ p %w[c++ lisp].map &:upcase.and_concat.with("er") # => ["C++er", "LISPer"]
@@ -0,0 +1,6 @@
1
+ require 'give4each'
2
+
3
+ # %w[c++ lisp].map do |a|
4
+ # a.concat("er").upcase
5
+ # end
6
+ %w[c++ lisp].map &:upcase.of_concat.with("er") # => ["C++ER", "LISPER"]
@@ -0,0 +1,5 @@
1
+ require 'give4each'
2
+ # (1..5).map do |i|
3
+ # i ** 2
4
+ # end
5
+ (1..5).map &:**.with(2) # => [1, 4, 9, 16, 25]
@@ -0,0 +1,9 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ module Give4Each
4
+ VERSION = "0.0.1"
5
+ end
6
+
7
+ require "give4each/private_helpers"
8
+ require "give4each/method_chain"
9
+ require "give4each/core_ext"
@@ -0,0 +1,22 @@
1
+ class Symbol
2
+
3
+ # Create new Give4Each::MethodChain with the Symbol and +args+ and +block+.
4
+ # *example*:
5
+ # :include: examples/with.rb
6
+ def with *args, &block
7
+ Give4Each::MethodChain.new self, *args, &block
8
+ end
9
+
10
+ # Examples::
11
+ # *of_\**:
12
+ # :include: examples/of.rb
13
+ # *and_\**:
14
+ # :include: examples/and.rb
15
+ def method_missing f, *a, &b
16
+ if Give4Each.allowing_method? f
17
+ Give4Each::MethodChain.new(self).send f, *a, &b
18
+ else
19
+ super
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,57 @@
1
+
2
+ require 'give4each/private_helpers'
3
+
4
+ class Give4Each::MethodChain
5
+
6
+ HasArgs = Struct.new :method, :args, :block
7
+
8
+ # for example,
9
+ # Give4Eeach::MethodChain.new :any, *args, &block
10
+ # as the:
11
+ # :any.with *args, &block
12
+ def initialize method, *args, &block
13
+ raise TypeError, "#{self.class} need to the symbol of the method." unless method.respond_to? :to_sym
14
+ @callings = [].push HasArgs.new method.to_sym, args, block
15
+ end
16
+
17
+ # Examples::
18
+ # *of_\**:
19
+ # :include: examples/of.rb
20
+ # *and_\**:
21
+ # :include: examples/and.rb
22
+ # You can do the same as +with+ if you pass the +args+.
23
+ # %w[c++ lisp].map &:upcase.and_concat("er") # => ["C++er", "LISPer"]
24
+ def method_missing method, *args, &block
25
+ case method.to_s
26
+ when /^of_(.*)$/
27
+ @current = HasArgs.new $1, args, block
28
+ @callings.unshift @current
29
+ when /^and_(.*)$/
30
+ @current = HasArgs.new $1, args, block
31
+ @callings.push @current
32
+ else super
33
+ end
34
+ self
35
+ end
36
+
37
+ # example:
38
+ # :include: examples/with.rb
39
+ def with *args, &block
40
+ @current.args = args
41
+ @current.block = block
42
+ self
43
+ end
44
+
45
+ def to_sym
46
+ @method
47
+ end
48
+
49
+ def to_proc
50
+ proc do |o, *a, &b|
51
+ @callings.inject o do |o, has|
52
+ o.send has.method, *has.args, &has.block
53
+ end
54
+ end
55
+ end
56
+
57
+ end
@@ -0,0 +1,15 @@
1
+ module Give4Each; end
2
+
3
+ module Give4Each::PrivateHelpers # :nodoc: all
4
+
5
+ def allowing_method? f
6
+ [/^of_.*$/, /^and_.*$/].any? { |a| f.to_s =~ a } or
7
+ [:with].include? f.to_sym
8
+ end
9
+
10
+ end
11
+
12
+ module Give4Each
13
+ include Give4Each::PrivateHelpers
14
+ extend self
15
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: give4each
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - pasberth
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rdoc
16
+ requirement: &70132470706940 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.10'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70132470706940
25
+ - !ruby/object:Gem::Dependency
26
+ name: hoe
27
+ requirement: &70132470706320 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '2.13'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70132470706320
36
+ description: ''
37
+ email:
38
+ - pasberth@gmail.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files:
42
+ - History.txt
43
+ files:
44
+ - lib/give4each.rb
45
+ - lib/give4each/core_ext.rb
46
+ - lib/give4each/method_chain.rb
47
+ - lib/give4each/private_helpers.rb
48
+ - History.txt
49
+ - README.rdoc
50
+ - Rakefile
51
+ - examples/and.rb
52
+ - examples/example.rb
53
+ - examples/of.rb
54
+ - examples/with.rb
55
+ - .gemtest
56
+ homepage:
57
+ licenses: []
58
+ post_install_message:
59
+ rdoc_options:
60
+ - --main
61
+ - README.rdoc
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project: give4each
78
+ rubygems_version: 1.8.10
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: ''
82
+ test_files: []