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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 028aefd79743422aa1e099ba360099b8195080a4
4
- data.tar.gz: fef7d4cd84cb13f157133ca2c71a0c9148a8479c
3
+ metadata.gz: b8604c795cdfac60ef4c57d18e1fd7df61817540
4
+ data.tar.gz: 5f238687507445c9b448e66eeeaad3e75a37e7fd
5
5
  SHA512:
6
- metadata.gz: b17bebb308b74058fedcd8a4dee757058347ba1e968f089c23b1e8081f9cb09fec00f2bdff13fc68ef626ffe4a1bff1c4f8eea9035586eae67d31548b4e3c6b5
7
- data.tar.gz: c73f4623f9af802c1cbf684a8f30bd20a6cd976392f3e6621152118f6a095bb56f6b289803b46a5eca812474b12a88594d065fd5c4a2a4e6edaab35ea8c447d3
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 value, behavior=nil, &blk
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
@@ -1,5 +1,5 @@
1
1
  module Lab42
2
2
  module Core
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
4
4
  end # module Core
5
5
  end # module Lab42
data/lib/lab42/core.rb CHANGED
@@ -3,3 +3,4 @@ require 'lab42/core/enumerable'
3
3
  require 'lab42/core/hash'
4
4
  require 'lab42/core/kernel'
5
5
  require 'lab42/core/object'
6
+ require 'lab42/core/module'
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.5
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-10-11 00:00:00.000000000 Z
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