linked 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/linked/item.rb +31 -1
- data/lib/linked/list.rb +22 -0
- data/lib/linked/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d85491962a16ae84236a5e278940ba46b6b29c65
|
4
|
+
data.tar.gz: 97acd2defdcb3d1a983a29582daaadf3019ca317
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f8fc6b24885ac1d7f66b7bbf273bf4744bc765f41b33b6ca71c41e4dc5d3ad0f8cdd37976b2730a79594661d93d6a77dba43155c2e2f8def5b42b650b99c28e
|
7
|
+
data.tar.gz: fb1a283dfa52704de58e93843a5fedefa86275f2b5be514575f3baef1a3610caacbbbefeba49373257e4863215464a4f57273619898e8a0ec22029f44eb995e1
|
data/lib/linked/item.rb
CHANGED
@@ -24,7 +24,7 @@ module Linked
|
|
24
24
|
#
|
25
25
|
# Returns the item's list, or nil
|
26
26
|
|
27
|
-
|
27
|
+
attr_writer :list
|
28
28
|
protected :list=
|
29
29
|
|
30
30
|
# The Item can hold an arbitrary object as its value and it will stay with
|
@@ -71,6 +71,36 @@ module Linked
|
|
71
71
|
end
|
72
72
|
super
|
73
73
|
end
|
74
|
+
|
75
|
+
# Identity method that simply return the item. This method mirrors List#item
|
76
|
+
# and allows other methods that work on Item objects to easily and
|
77
|
+
# interchangebly accept both lists and items as arguments.
|
78
|
+
#
|
79
|
+
# Returns the item itself.
|
80
|
+
|
81
|
+
def item
|
82
|
+
self
|
83
|
+
end
|
84
|
+
|
85
|
+
# Access the list that the item is part of. If the item is not in a list a
|
86
|
+
# NoMethodError will be raised. This mirrors the behaviour of List#list and
|
87
|
+
# allows other methods that work on List objects to easily and
|
88
|
+
# interchangeably accept both lists and items as arguments.
|
89
|
+
#
|
90
|
+
# Returns the list that the item is part of.
|
91
|
+
|
92
|
+
def list
|
93
|
+
raise NoMethodError unless @list
|
94
|
+
@list
|
95
|
+
end
|
96
|
+
|
97
|
+
# Check it the item is part of a list.
|
98
|
+
#
|
99
|
+
# Returns true if the item is in a list.
|
100
|
+
|
101
|
+
def in_list?
|
102
|
+
@list ? true : false
|
103
|
+
end
|
74
104
|
|
75
105
|
# Check if this is the first item in the list. It is crucial that tail#nil?
|
76
106
|
# returns true for the first item to be identified correctly.
|
data/lib/linked/list.rb
CHANGED
@@ -62,6 +62,28 @@ module Linked
|
|
62
62
|
|
63
63
|
super
|
64
64
|
end
|
65
|
+
|
66
|
+
# Identity method that simply return the list. This method mirrors Item#list
|
67
|
+
# and allows other methods that work on List objects to easily and
|
68
|
+
# interchangebly accept both lists and items as arguments.
|
69
|
+
#
|
70
|
+
# Returns the list itself.
|
71
|
+
|
72
|
+
def list
|
73
|
+
self
|
74
|
+
end
|
75
|
+
|
76
|
+
# Access the first item in the list. If the list is empty a NoMethodError
|
77
|
+
# will be raised. This mirrors the behaviour of Item#item and allows other
|
78
|
+
# methods that work on List objects to easily and interchangeably accept
|
79
|
+
# both lists and items as arguments.
|
80
|
+
#
|
81
|
+
# Returns the first item in the list.
|
82
|
+
|
83
|
+
def item
|
84
|
+
raise NoMethodError if empty?
|
85
|
+
eol.next
|
86
|
+
end
|
65
87
|
|
66
88
|
# Access the first n item(s) in the list. If a block is given each item will
|
67
89
|
# be yielded to it. The first item, starting from the first in the list, for
|
data/lib/linked/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: linked
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Lindberg
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|