mynyml-in_collection 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.
- data/LICENSE +19 -0
- data/README +15 -0
- data/Rakefile +57 -0
- data/lib/in_collection.rb +8 -0
- data/test/test_helper.rb +10 -0
- data/test/test_in_collection.rb +16 -0
- metadata +60 -0
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright © 2009 Martin Aumont (mynyml)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
7
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
8
|
+
so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Ever felt like [].include?(x) was "backwards"?
|
2
|
+
Ever wanted to just go x.in?([]) instead?
|
3
|
+
|
4
|
+
[1,2,3].include? 1
|
5
|
+
1.in? [1,2,3]
|
6
|
+
|
7
|
+
post.comments.include?(comment)
|
8
|
+
comment.in?(post.comments)
|
9
|
+
|
10
|
+
In Surrealist Coding that would be something like
|
11
|
+
|
12
|
+
| idiom(:include?).reverse - "clude" #~> #in? |
|
13
|
+
|
14
|
+
In real coding, well, it's intuitive. and fun!
|
15
|
+
And Python has in(), so why not Ruby?
|
data/Rakefile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# --------------------------------------------------
|
2
|
+
# tasks mostly copied from thin's Rakefile
|
3
|
+
# http://github.com/macournoyer/thin/tree/master
|
4
|
+
# --------------------------------------------------
|
5
|
+
|
6
|
+
require 'rake/gempackagetask'
|
7
|
+
require 'pathname'
|
8
|
+
require 'yaml'
|
9
|
+
|
10
|
+
RUBY_1_9 = RUBY_VERSION =~ /^1\.9/
|
11
|
+
WIN = (RUBY_PLATFORM =~ /mswin|cygwin/)
|
12
|
+
SUDO = (WIN ? "" : "sudo")
|
13
|
+
|
14
|
+
def gem
|
15
|
+
RUBY_1_9 ? 'gem19' : 'gem'
|
16
|
+
end
|
17
|
+
|
18
|
+
def all_except(paths)
|
19
|
+
Dir['**/*'] - paths.map {|path| path.strip.gsub(/^\//,'').gsub(/\/$/,'') }
|
20
|
+
end
|
21
|
+
|
22
|
+
spec = Gem::Specification.new do |s|
|
23
|
+
s.name = 'in_collection'
|
24
|
+
s.version = '0.1'
|
25
|
+
s.summary = '3.in? [1,2,3] #<=> [1,2,3].include? 3'
|
26
|
+
s.description = "Simple Ruby lib that provides an #in? method to objects, a mirror equivalent to #include?. which sometimes just makes you happier. Happiness is good."
|
27
|
+
s.author = "Martin Aumont"
|
28
|
+
s.email = 'mynyml@gmail.com'
|
29
|
+
s.homepage = ''
|
30
|
+
s.has_rdoc = true
|
31
|
+
s.require_path = "lib"
|
32
|
+
s.files = Dir['**/*']
|
33
|
+
end
|
34
|
+
|
35
|
+
Rake::GemPackageTask.new(spec) do |p|
|
36
|
+
p.gem_spec = spec
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
desc "Remove package products"
|
41
|
+
task :clean => :clobber_package
|
42
|
+
|
43
|
+
desc "Update the gemspec for GitHub's gem server"
|
44
|
+
task :gemspec do
|
45
|
+
Pathname("#{spec.name}.gemspec").open('w') {|f| f << YAML.dump(spec) }
|
46
|
+
end
|
47
|
+
|
48
|
+
desc "Install gem"
|
49
|
+
task :install => [:clobber, :package] do
|
50
|
+
sh "#{SUDO} #{gem} install pkg/#{spec.full_name}.gem"
|
51
|
+
end
|
52
|
+
|
53
|
+
desc "Uninstall gem"
|
54
|
+
task :uninstall => :clean do
|
55
|
+
sh "#{SUDO} #{gem} uninstall -v #{spec.version} -x #{spec.name}"
|
56
|
+
end
|
57
|
+
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
root = Pathname(__FILE__).dirname.parent
|
3
|
+
require root.join('test/test_helper')
|
4
|
+
require root.join('lib/in_collection')
|
5
|
+
|
6
|
+
class InCollectionTest < Test::Unit::TestCase
|
7
|
+
context "Object#in" do
|
8
|
+
|
9
|
+
expect { 1.in?( [1,2,3] ).to be(true) }
|
10
|
+
expect { 7.in?( [1,2,3] ).to be(false) }
|
11
|
+
|
12
|
+
test "raises if argument isn't a collection" do
|
13
|
+
lambda { 1.in?(100) }.should raise_error(ArgumentError)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mynyml-in_collection
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.1"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Martin Aumont
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-03-28 21:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: "Simple Ruby lib that provides an #in? method to objects, a mirror equivalent to #include?. which sometimes just makes you happier. Happiness is good."
|
17
|
+
email: mynyml@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- lib
|
26
|
+
- lib/in_collection.rb
|
27
|
+
- LICENSE
|
28
|
+
- README
|
29
|
+
- Rakefile
|
30
|
+
- test
|
31
|
+
- test/test_helper.rb
|
32
|
+
- test/test_in_collection.rb
|
33
|
+
has_rdoc: true
|
34
|
+
homepage: ""
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "0"
|
45
|
+
version:
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
requirements: []
|
53
|
+
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 1.2.0
|
56
|
+
signing_key:
|
57
|
+
specification_version: 2
|
58
|
+
summary: "3.in? [1,2,3] #<=> [1,2,3].include? 3"
|
59
|
+
test_files: []
|
60
|
+
|