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 +4 -4
- data/README.md +5 -3
- data/lib/duckpond/duck.rb +24 -11
- data/lib/duckpond/sighting.rb +1 -0
- data/lib/duckpond/version.rb +1 -1
- data/spec/duck_spec.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b23a24b35895377f4668b651a7aaa75dcbd77054
|
4
|
+
data.tar.gz: 9be4575cb42cf0ffbb398cb78ecac73c178f3ba0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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"
|
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
|
-
|
68
|
-
|
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(
|
22
|
-
|
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
|
-
#
|
44
|
+
# add_quacks_from
|
27
45
|
#
|
28
|
-
#
|
29
|
-
# another duck.
|
46
|
+
# add the quacks from another duck
|
30
47
|
#
|
31
|
-
def
|
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
|
data/lib/duckpond/sighting.rb
CHANGED
data/lib/duckpond/version.rb
CHANGED
data/spec/duck_spec.rb
CHANGED
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.
|
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.
|
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:
|