boost_lambda_style_proc 1.0.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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +33 -0
- data/Rakefile +2 -0
- data/boost_lambda_style_proc.gemspec +18 -0
- data/lib/boost_lambda_style_proc.rb +43 -0
- data/lib/boost_lambda_style_proc/version.rb +3 -0
- data/spec/boost_lambda_style_proc_spec.rb +27 -0
- metadata +72 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2012 todesking
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# BoostLambdaStyleProc
|
|
2
|
+
|
|
3
|
+
This gem support to write a proc with Boost::Lambda style.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
gem 'boost_lambda_style_proc'
|
|
10
|
+
|
|
11
|
+
And then execute:
|
|
12
|
+
|
|
13
|
+
$ bundle
|
|
14
|
+
|
|
15
|
+
Or install it yourself as:
|
|
16
|
+
|
|
17
|
+
$ gem install boost_lambda_style_proc
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
# Without the gem
|
|
22
|
+
[1, 2, 3].map {|x| x * 2}
|
|
23
|
+
|
|
24
|
+
# With the gem
|
|
25
|
+
[1, 2, 3].map &(_1 * 2)
|
|
26
|
+
|
|
27
|
+
## Contributing
|
|
28
|
+
|
|
29
|
+
1. Fork it
|
|
30
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
31
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
|
32
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
33
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
require File.expand_path('../lib/boost_lambda_style_proc/version', __FILE__)
|
|
3
|
+
|
|
4
|
+
Gem::Specification.new do |gem|
|
|
5
|
+
gem.authors = ["todesking"]
|
|
6
|
+
gem.email = ["discommunicative@gmail.com"]
|
|
7
|
+
gem.summary = %q{Boost::Lambda style proc}
|
|
8
|
+
gem.homepage = ""
|
|
9
|
+
|
|
10
|
+
gem.files = `git ls-files`.split($\)
|
|
11
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
|
12
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
13
|
+
gem.name = "boost_lambda_style_proc"
|
|
14
|
+
gem.require_paths = ["lib"]
|
|
15
|
+
gem.version = BoostLambdaStyleProc::VERSION
|
|
16
|
+
|
|
17
|
+
gem.add_development_dependency 'rspec'
|
|
18
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module BoostLambdaStyleProc
|
|
2
|
+
class Base
|
|
3
|
+
def method_missing name, *args
|
|
4
|
+
Expression.new(self, name, args)
|
|
5
|
+
end
|
|
6
|
+
end
|
|
7
|
+
class Argument < Base
|
|
8
|
+
def initialize(n)
|
|
9
|
+
@n = n
|
|
10
|
+
end
|
|
11
|
+
def to_proc
|
|
12
|
+
::Proc.new {|*args|
|
|
13
|
+
args[@n - 1]
|
|
14
|
+
}
|
|
15
|
+
end
|
|
16
|
+
def inspect
|
|
17
|
+
"_#{@n}"
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
class Expression < Base
|
|
21
|
+
def initialize receiver, method_name, args
|
|
22
|
+
@receiver = receiver
|
|
23
|
+
@method_name = method_name
|
|
24
|
+
@args = args
|
|
25
|
+
end
|
|
26
|
+
def to_proc
|
|
27
|
+
::Proc.new {|*outer_args|
|
|
28
|
+
@receiver.to_proc[*outer_args].__send__(@method_name, *@args.map {|a| case a when Base then a.to_proc[*outer_args] else a end })
|
|
29
|
+
}
|
|
30
|
+
end
|
|
31
|
+
def inspect
|
|
32
|
+
"(#{@receiver.inspect}).#{@method_name}(#{@args.map(&:inspect)*', '})"
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
module Kernel
|
|
38
|
+
(1..9).each do |n|
|
|
39
|
+
define_method :"_#{n}" do
|
|
40
|
+
BoostLambdaStyleProc::Argument.new(n)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require File.expand_path('../../lib/boost_lambda_style_proc.rb', __FILE__)
|
|
2
|
+
|
|
3
|
+
describe BoostLambdaStyleProc do
|
|
4
|
+
describe BoostLambdaStyleProc::Argument do
|
|
5
|
+
it 'Kernel#_{n} is shorthand for BoostLambdaStyleProc::Argument.new(n)' do
|
|
6
|
+
_1.should be_a(BoostLambdaStyleProc::Argument)
|
|
7
|
+
end
|
|
8
|
+
it 'can create proc that returns n-th(1 origin) argument' do
|
|
9
|
+
_2.to_proc[1,2,3].should == 2
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it 'can create Expression by call method' do
|
|
13
|
+
(_1 + _2).should be_a(BoostLambdaStyleProc::Expression)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe BoostLambdaStyleProc::Expression do
|
|
18
|
+
it 'can create proc' do
|
|
19
|
+
(_1 + _2).to_proc[1, 2].should == 3
|
|
20
|
+
|
|
21
|
+
[1, 2, 3].map(&(_1 * 2 + 3)).should == [5, 7, 9]
|
|
22
|
+
|
|
23
|
+
[2, 4, 6].should be_all(&(_1.even?))
|
|
24
|
+
[1, 4, 6].should_not be_all(&(_1.even?))
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: boost_lambda_style_proc
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- todesking
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2012-08-21 00:00:00.000000000Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: rspec
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '0'
|
|
22
|
+
type: :development
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ! '>='
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '0'
|
|
30
|
+
description:
|
|
31
|
+
email:
|
|
32
|
+
- discommunicative@gmail.com
|
|
33
|
+
executables: []
|
|
34
|
+
extensions: []
|
|
35
|
+
extra_rdoc_files: []
|
|
36
|
+
files:
|
|
37
|
+
- .gitignore
|
|
38
|
+
- Gemfile
|
|
39
|
+
- LICENSE
|
|
40
|
+
- README.md
|
|
41
|
+
- Rakefile
|
|
42
|
+
- boost_lambda_style_proc.gemspec
|
|
43
|
+
- lib/boost_lambda_style_proc.rb
|
|
44
|
+
- lib/boost_lambda_style_proc/version.rb
|
|
45
|
+
- spec/boost_lambda_style_proc_spec.rb
|
|
46
|
+
homepage: ''
|
|
47
|
+
licenses: []
|
|
48
|
+
post_install_message:
|
|
49
|
+
rdoc_options: []
|
|
50
|
+
require_paths:
|
|
51
|
+
- lib
|
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
53
|
+
none: false
|
|
54
|
+
requirements:
|
|
55
|
+
- - ! '>='
|
|
56
|
+
- !ruby/object:Gem::Version
|
|
57
|
+
version: '0'
|
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
|
+
none: false
|
|
60
|
+
requirements:
|
|
61
|
+
- - ! '>='
|
|
62
|
+
- !ruby/object:Gem::Version
|
|
63
|
+
version: '0'
|
|
64
|
+
requirements: []
|
|
65
|
+
rubyforge_project:
|
|
66
|
+
rubygems_version: 1.8.19
|
|
67
|
+
signing_key:
|
|
68
|
+
specification_version: 3
|
|
69
|
+
summary: Boost::Lambda style proc
|
|
70
|
+
test_files:
|
|
71
|
+
- spec/boost_lambda_style_proc_spec.rb
|
|
72
|
+
has_rdoc:
|