wref 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e9470b819c7b11a7787df0b977af91b0d1a20af2
4
- data.tar.gz: 1abbd729851f77a36f5ebe0f8def73d73b5bd8d3
3
+ metadata.gz: 8fd35b6dde49ae9d2e93ba05435a677d1289a1ad
4
+ data.tar.gz: c8d2a3520f12ac4e9d0b38283a5642bd033fb8f7
5
5
  SHA512:
6
- metadata.gz: 5c6fb6e08a0822a3d8a09b73f1390040b73af795dee23a2921e6600f28be809d6d05c9b321bb7f9b11b715e2f30dbca964b23269ee357da9ec85f447e6096a57
7
- data.tar.gz: d5fa295fd268ee4e1f995384ff1c1e850b8c702d23804dd816b646d6775bf8f482e3a694f4ef652281468482813bfca3654050977ab41c0d6ed4f15898ba9f90
6
+ metadata.gz: 1cff6d3ca7ca87cb73c5cd8d2b34de4992cf4e00d0a98f079e847f0211126e1749318a76c150176d7c459346e3d394c1164da064c748e13363fbd0c3337988b6
7
+ data.tar.gz: 232ca024fbf7e8e9c4657fe07d383a6ff2aafdb5fb62526a84233ab67e8e628fd784463d71a49074770156dac9ac46dbd1d0d99c5815622d049b2d305c6e2059
data/README.md CHANGED
@@ -29,23 +29,70 @@ weak_ref = Wref.new(str)
29
29
  weak_ref.alive? #=> true | false
30
30
  ```
31
31
 
32
- ### Weak map
32
+ ### Spawn a weak map
33
33
 
34
34
  ```ruby
35
35
  weak_map = Wref::Map.new
36
+ ```
37
+
38
+ ### Set a key and value in a weak map
39
+
40
+ ```ruby
41
+ str = "Test"
36
42
  map[1] = str
43
+ map.set(1, str)
44
+ ```
45
+
46
+ ### Get values from a weak map
47
+
48
+ ```ruby
49
+ map.get(1) #=> "Test" | nil
50
+ map.get!(1) #=> "Test" | Wref::Recycled error
51
+ ```
52
+
53
+ ### Loop over all valid pairs in a weak map
54
+
55
+ ```ruby
56
+ map.each do |key, value|
57
+ puts "Valid pair: #{key}: #{value}"
58
+ end
37
59
  ```
38
60
 
39
61
  ### Check if key is valid in a weak map.
40
62
 
41
63
  ```ruby
42
- weak_map.valid?(1) #=> true | false
64
+ map.valid?(1) #=> true | false
65
+ ```
66
+
67
+ ### Getting length of both valid and invalid and the current time in a weak map (fastest)
68
+
69
+ ```ruby
70
+ map.length #=> 1
71
+ ```
72
+
73
+ ### Getting length of valid options in a weak map
74
+
75
+ ```ruby
76
+ map.length_valid #=> 0
43
77
  ```
44
78
 
45
79
  ### Get from a key
46
80
 
47
81
  ```ruby
48
- weak_map.get(1) #=> "Test" | Error - Wref::Recycled
82
+ map.get(1) #=> "Test" | nil
83
+ map.get!(1) #=> "Test" | Error - Wref::Recycled
84
+ ```
85
+
86
+ ### Delete a key from a weak map
87
+
88
+ ```ruby
89
+ map.delete(1) #=> "Test" | nil if recycled
90
+ ```
91
+
92
+ ### Delete all recycled options
93
+
94
+ ```ruby
95
+ map.clean
49
96
  ```
50
97
 
51
98
  ## Contributing to wref
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.7
1
+ 0.0.8
@@ -14,7 +14,13 @@ class Wref::Implementations::IdClassUnique
14
14
 
15
15
  def get
16
16
  return nil if !@class_name || !@id
17
- object = ObjectSpace._id2ref(@id)
17
+
18
+ begin
19
+ object = ObjectSpace._id2ref(@id)
20
+ rescue RangeError
21
+ destroy
22
+ return nil
23
+ end
18
24
 
19
25
  #Some times this class-name will be nil for some reason - knj
20
26
  object_class_name = object.class.name
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: wref 0.0.7 ruby lib
5
+ # stub: wref 0.0.8 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "wref"
9
- s.version = "0.0.7"
9
+ s.version = "0.0.8"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Kasper Johansen"]
14
- s.date = "2015-04-08"
14
+ s.date = "2015-04-13"
15
15
  s.description = "Lightweight weak reference and weak hash that works in 1.9 and JRuby."
16
16
  s.email = "k@spernj.org"
17
17
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wref
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kasper Johansen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-08 00:00:00.000000000 Z
11
+ date: 2015-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec