epitools 0.5.32 → 0.5.33

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: c0b663423844dcefe3e743a90a86cbcaab0ab460
4
- data.tar.gz: 9a874aa31d99c415751afaed0b29542ae520cf1d
3
+ metadata.gz: 3ef87f5b481da8299d67f99558bdd36e980a1f01
4
+ data.tar.gz: 8d0d98bb58b957051f1b8376ff748e4d08a7f88f
5
5
  SHA512:
6
- metadata.gz: 1509cff967e02c20eaa9779f8608f86c3d97ffd7f84d8d1910dc492b6d0ff5eacbb655ba7af647f9dfb4b5cbdcf484f07336714344f61b22d9d7afb8bedc47a2
7
- data.tar.gz: 06244532a2aa98d81bb1b1d6a243e2dc09e4855e8b04a5af4d71a537cf27d5fec0bddef7fc6e766c46e1ed07fd3fd6abbb314ac0546215d702a7dca29ca264ab
6
+ metadata.gz: 08f077990e8518946eb3b0b0d30bc4f09b3daa867f386fa92ca183b38e5aa5c483ac1b8625ae9f7c2d6f95afe2e1a612fec68231d108f81fd0eb963f461a4989
7
+ data.tar.gz: bca8a6f90958e61e8f3f371effdee9d2e80ca6bb4b6511416bf552330861ff23cf7d13029f5514fe1646aa91f5269652311eac73bc3d78b2ea1b0521951d787c
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.32
1
+ 0.5.33
@@ -4,7 +4,7 @@ class Numeric
4
4
 
5
5
  def truthy?; self > 0; end
6
6
 
7
- def commatize
7
+ def commatize
8
8
  to_s.gsub(/(\d)(?=\d{3}+(?:\.|$))(\d{3}\..*)?/,'\1,\2')
9
9
  end
10
10
 
@@ -58,7 +58,26 @@ class Object
58
58
  copy
59
59
  end
60
60
  end
61
-
61
+
62
+ #
63
+ # Cache (memoize) the result of this method the first time it's called
64
+ # and return this value for all subsequent calls.
65
+ #
66
+ def self.memoize(*methods)
67
+ methods.each do |meth|
68
+ old_method = instance_method(meth)
69
+
70
+ if old_method.arity == 0
71
+ ivarname = "@#{meth}"
72
+ define_method meth do
73
+ instance_variable_get(ivarname) or instance_variable_set(ivarname, old_method.bind(self).call)
74
+ end
75
+ else
76
+ raise "Can't memoize methods with arguments. (YET.)"
77
+ end
78
+ end
79
+ end
80
+
62
81
  #
63
82
  # Serialize this object to a binary String, using Marshal.dump.
64
83
  #
data/lib/epitools/path.rb CHANGED
@@ -351,7 +351,7 @@ class Path
351
351
  end
352
352
 
353
353
  def symlink_target
354
- Path.new File.readlink(path)
354
+ Path.new File.readlink(path.gsub(/\/$/, ''))
355
355
  end
356
356
  alias_method :readlink, :symlink_target
357
357
 
@@ -96,6 +96,29 @@ describe Object do
96
96
  a.map(&:self).should == a
97
97
  end
98
98
 
99
+ it "memoizes" do
100
+
101
+ class Fake
102
+
103
+ def cacheme
104
+ @temp = !@temp
105
+ end
106
+ memoize :cacheme
107
+
108
+ end
109
+
110
+ f = Fake.new
111
+ f.instance_variable_get("@cacheme").should == nil
112
+
113
+ f.cacheme.should == true
114
+ f.instance_variable_get("@temp").should == true
115
+ f.instance_variable_get("@cacheme").should == true
116
+
117
+ f.cacheme.should == true
118
+ f.instance_variable_get("@temp").should == true
119
+ f.instance_variable_get("@cacheme").should == true
120
+ end
121
+
99
122
  end
100
123
 
101
124
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epitools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.32
4
+ version: 0.5.33
5
5
  platform: ruby
6
6
  authors:
7
7
  - epitron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-07 00:00:00.000000000 Z
11
+ date: 2013-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec