included-in 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ * v 0.2.1
2
+
3
+ Changed the way it checks for error to reduce the upfront cost of checking #respond_to? and now just catching NoMethodError (no additional cost)
4
+
1
5
  * v 0.2.0
2
6
 
3
- Mimics the way ActiveSupport 3.1 calls the method and organizes the code. Object#included_in? => Object#in?
7
+ Mimics the way ActiveSupport 3.1 calls the method and organizes the code. Object#included_in? => Object#in?
8
+
data/Manifest CHANGED
@@ -1,8 +1,11 @@
1
1
  CHANGELOG
2
2
  README.rdoc
3
3
  Rakefile
4
+ included-in.gemspec
4
5
  init.rb
5
6
  lib/included_in.rb
6
7
  lib/included_in/object.rb
7
8
  lib/included_in/object/inclusion.rb
9
+ spec/included_in/object/inclusion_spec.rb
10
+ spec/spec_helper.rb
8
11
  Manifest
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('included-in', '0.2.0') do |p|
5
+ Echoe.new('included-in', '0.2.1') do |p|
6
6
  p.description = "Adds an included_in? method to Object for a more readable syntax of include?"
7
7
  p.url = "https://github.com/jaredonline/included-in"
8
8
  p.author = "Jared McFarland"
@@ -2,16 +2,16 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{included-in}
5
- s.version = "0.2.0"
5
+ s.version = "0.2.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Jared McFarland"]
9
9
  s.cert_chain = ["/Users/jared/gems/keys/gem-public_cert.pem"]
10
- s.date = %q{2011-04-13}
10
+ s.date = %q{2011-04-14}
11
11
  s.description = %q{Adds an included_in? method to Object for a more readable syntax of include?}
12
12
  s.email = %q{jared.online@gmail.com}
13
13
  s.extra_rdoc_files = ["CHANGELOG", "README.rdoc", "lib/included_in.rb", "lib/included_in/object.rb", "lib/included_in/object/inclusion.rb"]
14
- s.files = ["CHANGELOG", "README.rdoc", "Rakefile", "init.rb", "lib/included_in.rb", "lib/included_in/object.rb", "lib/included_in/object/inclusion.rb", "Manifest", "included-in.gemspec"]
14
+ s.files = ["CHANGELOG", "README.rdoc", "Rakefile", "included-in.gemspec", "init.rb", "lib/included_in.rb", "lib/included_in/object.rb", "lib/included_in/object/inclusion.rb", "spec/included_in/object/inclusion_spec.rb", "spec/spec_helper.rb", "Manifest"]
15
15
  s.homepage = %q{https://github.com/jaredonline/included-in}
16
16
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Included-in", "--main", "README.rdoc"]
17
17
  s.require_paths = ["lib"]
@@ -1,9 +1,16 @@
1
1
  class Object
2
-
2
+ # Returns true if this object is included in the argument. Argument must be
3
+ # any object which respond to +#include?+. Usage:
4
+ #
5
+ # characters = ["Konata", "Kagami", "Tsukasa"]
6
+ # "Konata".in?(characters) # => true
7
+ #
8
+ # This will throw an ArgumentError if the supplied argument doesnt not respond
9
+ # to +#include?+.
3
10
  def in?(object)
4
- raise ArgumentError.new("You must supply an argument that responds to include?") unless object.respond_to?(:include?)
5
-
6
11
  object.include?(self)
12
+ rescue NoMethodError
13
+ raise ArgumentError.new("The parameter passed to #in? must respond to #include?")
7
14
  end
8
15
 
9
16
  def included_in?(object)
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ describe Object do
4
+ # test modules for later
5
+ module A
6
+ end
7
+ class B
8
+ include A
9
+ end
10
+ class C < B
11
+ end
12
+
13
+ it "should respond to in?" do
14
+ object = Object.new
15
+ object.respond_to?(:in?).should == true
16
+ end
17
+
18
+ context 'it is included in another object' do
19
+ it "should return true for an array" do
20
+ 1.in?([1, 2]).should == true
21
+ end
22
+
23
+ it "should return true for a hash" do
24
+ "a".in?({"a" => 100, "b" => 200}).should == true
25
+ end
26
+
27
+ it "should return true for a string" do
28
+ "lo".in?("Hello").should == true
29
+ end
30
+
31
+ it "should return true for a set" do
32
+ 4.in?(1..10).should == true
33
+ end
34
+
35
+ it "should return true for a module" do
36
+ A.in?(B).should == true
37
+ end
38
+ end
39
+
40
+ context 'it is not included in another object' do
41
+ it "should return false for an array" do
42
+ 1.in?([3, 4]).should == false
43
+ end
44
+
45
+ it "should return false for a hash" do
46
+ "a".in?({"c" => 300, "d" => 400}).should == false
47
+ end
48
+
49
+ it "should return false for a string" do
50
+ "World".in?("Hello").should == false
51
+ end
52
+
53
+ it "should return false for a set" do
54
+ 1.in?(5..10).should == false
55
+ end
56
+
57
+ it "should return false for a module" do
58
+ A.in?(A).should == false
59
+ end
60
+ end
61
+
62
+ context 'supplied object does not respond to #include?' do
63
+ it 'should raise an argument error' do
64
+ lambda { 1.in?(1) }.should raise_error ArgumentError
65
+ end
66
+ end
67
+
68
+ end
@@ -0,0 +1 @@
1
+ require 'included_in'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: included-in
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jared McFarland
@@ -36,7 +36,7 @@ cert_chain:
36
36
  ncO2Ggxc146uqG0Yz4o=
37
37
  -----END CERTIFICATE-----
38
38
 
39
- date: 2011-04-13 00:00:00 -07:00
39
+ date: 2011-04-14 00:00:00 -07:00
40
40
  default_executable:
41
41
  dependencies: []
42
42
 
@@ -56,12 +56,14 @@ files:
56
56
  - CHANGELOG
57
57
  - README.rdoc
58
58
  - Rakefile
59
+ - included-in.gemspec
59
60
  - init.rb
60
61
  - lib/included_in.rb
61
62
  - lib/included_in/object.rb
62
63
  - lib/included_in/object/inclusion.rb
64
+ - spec/included_in/object/inclusion_spec.rb
65
+ - spec/spec_helper.rb
63
66
  - Manifest
64
- - included-in.gemspec
65
67
  has_rdoc: true
66
68
  homepage: https://github.com/jaredonline/included-in
67
69
  licenses: []
metadata.gz.sig CHANGED
Binary file