1_as_identity_function 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/1_as_identity_function.gemspec +20 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +40 -0
- data/Rakefile +1 -0
- data/lib/1_as_identity_function.rb +17 -0
- data/spec/1_as_identity_function_spec.rb +22 -0
- metadata +71 -0
data/.gitignore
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "1_as_identity_function"
|
7
|
+
gem.version = '1.0.0'
|
8
|
+
gem.authors = ["todesking"]
|
9
|
+
gem.email = ["discommunicative@gmail.com"]
|
10
|
+
gem.description = %q{1.to_proc returns {|x| x}. COOL!!}
|
11
|
+
gem.summary = %q{[1, 2, 3].map(&1) return [1, 2, 3]. Whooo!!}
|
12
|
+
gem.homepage = ""
|
13
|
+
|
14
|
+
gem.files = `git ls-files`.split($/)
|
15
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
|
19
|
+
gem.add_development_dependency 'rspec'
|
20
|
+
end
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 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,40 @@
|
|
1
|
+
# 1\_as\_identity\_function
|
2
|
+
|
3
|
+
`1.to_proc` returns `lambda {|x| x}`
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem '1_as_identity_function'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install 1_as_identity_function
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
[1, 2, 3].map(&1)
|
23
|
+
=> [1, 2, 3]
|
24
|
+
```
|
25
|
+
|
26
|
+
Yeah.
|
27
|
+
|
28
|
+
## Contributing
|
29
|
+
|
30
|
+
1. Fork it
|
31
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
32
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
33
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
34
|
+
5. Create new Pull Request
|
35
|
+
|
36
|
+
## Changes
|
37
|
+
|
38
|
+
### 1.0.0
|
39
|
+
|
40
|
+
* initial release
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
class Fixnum
|
4
|
+
def to_proc
|
5
|
+
raise NoMethodError unless self == 1
|
6
|
+
lambda {|x| x}
|
7
|
+
end
|
8
|
+
def respond_to_with_1_as_identity_function?(name, include_private = false)
|
9
|
+
if name.to_s == 'to_proc'
|
10
|
+
return self == 1
|
11
|
+
else
|
12
|
+
return respond_to_without_1_as_identity_function?(name, include_private)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
alias respond_to_without_1_as_identity_function? respond_to?
|
16
|
+
alias respond_to? respond_to_with_1_as_identity_function?
|
17
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require '1_as_identity_function'
|
4
|
+
|
5
|
+
describe '1_as_identity_function' do
|
6
|
+
describe 1 do
|
7
|
+
subject { 1 }
|
8
|
+
it { should be_respond_to(:to_proc) }
|
9
|
+
describe '#to_proc' do
|
10
|
+
subject { 1.to_proc }
|
11
|
+
it { subject[1].should == 1 }
|
12
|
+
it { subject[:symbol].should == :symbol }
|
13
|
+
it { subject[nil].should == nil }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'Other Fixnum instances' do
|
18
|
+
subject { 2 }
|
19
|
+
it { should_not be_respond_to(:to_proc) }
|
20
|
+
it { expect { subject.to_proc }.to raise_error(NoMethodError) }
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: 1_as_identity_function
|
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: 2013-04-07 00:00:00.000000000 Z
|
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: 1.to_proc returns {|x| x}. COOL!!
|
31
|
+
email:
|
32
|
+
- discommunicative@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- 1_as_identity_function.gemspec
|
39
|
+
- Gemfile
|
40
|
+
- LICENSE.txt
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- lib/1_as_identity_function.rb
|
44
|
+
- spec/1_as_identity_function_spec.rb
|
45
|
+
homepage: ''
|
46
|
+
licenses: []
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.8.19
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: ! '[1, 2, 3].map(&1) return [1, 2, 3]. Whooo!!'
|
69
|
+
test_files:
|
70
|
+
- spec/1_as_identity_function_spec.rb
|
71
|
+
has_rdoc:
|