duckpond 1.0.0 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 515a4dbf8c5dfcc7ac533ebc75579053972755fe
4
- data.tar.gz: 2b99253f7d6f981e307a01fa324ba20d3bb0dc87
3
+ metadata.gz: b23a24b35895377f4668b651a7aaa75dcbd77054
4
+ data.tar.gz: 9be4575cb42cf0ffbb398cb78ecac73c178f3ba0
5
5
  SHA512:
6
- metadata.gz: 21b5db87d898f1c3759fed7c1beb9b254d57e32646daddaff7808d072ee42ca206d6f128b96656bd29d6996b1e565863ac0ca5a4aa1c14e43056ad751b3defae
7
- data.tar.gz: 8a4f5c3892a69fbc10bb59deee0d20f0bdec7e046fb31ce0076d7dc7b8eb7a8c8bd767b8469aa8aea676d9fd31c6f6193ded7b5e3b3a03f7d6afc903edf08f0e
6
+ metadata.gz: 37eb854f411be6a4480173f7a18fa94a0ef8886637f975714b1ec1ccad66cb9f6afbef019474a8ff4f269df7d41b28209afac03f947b14b4da4f7bcf3db495f5
7
+ data.tar.gz: c4a7d9df1277b9fad7083e1c5aa1e76e247891fa1311d366f2ba47082b9be5ef7d0bda5d6fe4af99a666458f3d0d6c05ef88dc8ad8b9f646f1e1dee8ae872cca
data/README.md CHANGED
@@ -61,13 +61,15 @@ There are other syntaxes:
61
61
  DuckPond::Binoculars.confirm!(obj, MyDuck)
62
62
 
63
63
 
64
- Ducks can be combined into composite "super ducks" using the looks_like method - ducks which are made up of various other ducks:
64
+ Ducks can be combined into composite "super ducks" - ducks which are made up of various other ducks:
65
65
 
66
66
  class MySuperDuck < DuckPond::Duck
67
- looks_like MyDuck
68
- looks_like MyOtherDuck
67
+ quacks_like MyDuck
68
+ quacks_like MyOtherDuck
69
69
  end
70
70
 
71
+ the quacks_like method has been aliased to looks_like too - you can say something looks_like or quacks_like any item, whichever you prefer (in case you didn't want "quack" methods in your ever so serious project!).
72
+
71
73
 
72
74
  ## Contributing
73
75
 
data/lib/duckpond/duck.rb CHANGED
@@ -16,28 +16,41 @@ module DuckPond
16
16
  # quacks_like
17
17
  #
18
18
  # Use this to specify that this duck quacks with
19
- # a certain method.
19
+ # a certain method, or quacks like another duck.
20
20
  #
21
- def quacks_like(method)
22
- quacks << method
21
+ def quacks_like(item)
22
+ if item.is_a? Symbol
23
+ quacks << item
24
+ elsif item.ancestors.include? DuckPond::Duck
25
+ add_quacks_from item
26
+ else
27
+ raise TypeError
28
+ end
29
+ end
30
+ alias :looks_like :quacks_like
31
+
32
+ #
33
+ # quacks_like?
34
+ #
35
+ # The main quack checking method for a duck
36
+ #
37
+ def quacks_like?(method)
38
+ quacks.include?(method)
23
39
  end
40
+ alias :looks_like? :quacks_like
24
41
 
42
+ private
25
43
  #
26
- # looks_like
44
+ # add_quacks_from
27
45
  #
28
- # Use this to specify that this duck looks like
29
- # another duck.
46
+ # add the quacks from another duck
30
47
  #
31
- def looks_like(other_duck)
48
+ def add_quacks_from(other_duck)
32
49
  other_duck.quacks.each do |other_ducks_quacking|
33
50
  quacks_like other_ducks_quacking
34
51
  end
35
52
  end
36
53
 
37
- def quacks_like?(method)
38
- quacks.include?(method)
39
- end
40
-
41
54
  end
42
55
  end
43
56
  end
@@ -32,5 +32,6 @@ module DuckPond
32
32
  end
33
33
  true
34
34
  end
35
+ alias :looks_like? :quacks_like?
35
36
  end
36
37
  end
@@ -1,3 +1,3 @@
1
1
  module Duckpond
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
data/spec/duck_spec.rb CHANGED
@@ -38,7 +38,7 @@ module DuckPond
38
38
  end
39
39
 
40
40
  class MySimilarDuck < Duck
41
- looks_like MyDuck
41
+ quacks_like MyDuck
42
42
  quacks_like :chunky_bacon
43
43
  end
44
44
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duckpond
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikey Hogarth
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  version: '0'
85
85
  requirements: []
86
86
  rubyforge_project:
87
- rubygems_version: 2.2.2
87
+ rubygems_version: 2.1.10
88
88
  signing_key:
89
89
  specification_version: 4
90
90
  summary: Explicit duck-typing for ruby
@@ -96,3 +96,4 @@ test_files:
96
96
  - spec/spec_helper.rb
97
97
  - spec/the_problem_spec.rb
98
98
  - spec/the_solution_spec.rb
99
+ has_rdoc: