lab42_core 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lab42/core/fn/iterator_reimpl.rb +3 -1
- data/lib/lab42/core/module.rb +37 -0
- data/lib/lab42/core/version.rb +1 -1
- data/lib/lab42/core.rb +1 -0
- 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: b8604c795cdfac60ef4c57d18e1fd7df61817540
|
4
|
+
data.tar.gz: 5f238687507445c9b448e66eeeaad3e75a37e7fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e95293ca068e18547faf0892b75512fa55382a54d62cfd989066dd9c6276ad4d4043a717701fb5da782018122e801141691bce9afb0b0ebf98435d46e52c972f
|
7
|
+
data.tar.gz: afbe49cb75fc522ad820ab333a468325767bfd505eda6630480d87f0deb41c233e7f256964507ce67ce5e160295c3662857a194cec658b18e51a6980138bfe56
|
@@ -24,7 +24,9 @@ module Lab42
|
|
24
24
|
end
|
25
25
|
|
26
26
|
alias_method :__lab42_core_iterator_inject__, :inject
|
27
|
-
def inject
|
27
|
+
def inject *args, &blk
|
28
|
+
return reduce(&blk) if args.empty?
|
29
|
+
value, behavior = args
|
28
30
|
if Symbol === behavior
|
29
31
|
__lab42_core_iterator_inject__ value, behavior
|
30
32
|
else
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class ::Module
|
2
|
+
|
3
|
+
def memoize name, by: ->(n){n}
|
4
|
+
im = instance_method name
|
5
|
+
cache = {}
|
6
|
+
mcache = {}
|
7
|
+
# Replace method by the memoized version
|
8
|
+
#
|
9
|
+
remove_method name
|
10
|
+
define_method name do |*args, &blk|
|
11
|
+
cache[object_id] ||= {}
|
12
|
+
mcache[object_id] ||= im.bind self
|
13
|
+
key = by.(*args,&blk)
|
14
|
+
|
15
|
+
return cache[object_id][key] if cache[object_id].has_key? key
|
16
|
+
rval = mcache[object_id].(*args, &blk)
|
17
|
+
cache[object_id][key] = rval
|
18
|
+
end
|
19
|
+
wm = instance_method name
|
20
|
+
# Create a one time wrapper for cache initialization
|
21
|
+
remove_method name
|
22
|
+
wrapper = ->(*args,&blk) do
|
23
|
+
cache[object_id] = {}
|
24
|
+
class << self; self end.module_eval do
|
25
|
+
define_method name, wm
|
26
|
+
end
|
27
|
+
result = wm.bind(self).(*args, &blk)
|
28
|
+
# reinstall the wrapper
|
29
|
+
class << self; self end.module_eval do
|
30
|
+
define_method( name, &wrapper )
|
31
|
+
end
|
32
|
+
result
|
33
|
+
end
|
34
|
+
define_method( name, &wrapper )
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
data/lib/lab42/core/version.rb
CHANGED
data/lib/lab42/core.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lab42_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Dober
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- lib/lab42/core/fn/iterator_reimpl.rb
|
52
52
|
- lib/lab42/core/fn/enumerable.rb
|
53
53
|
- lib/lab42/core/dir.rb
|
54
|
+
- lib/lab42/core/module.rb
|
54
55
|
- lib/lab42/core/version.rb
|
55
56
|
- lib/lab42/core/fn.rb
|
56
57
|
- lib/lab42/core/hash.rb
|