curryer 0.0.1 → 0.0.2

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/curryer.rb +12 -16
  3. data/lib/curryer/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f816271ae0ce4b1eb55f721b662461027ea4a630
4
- data.tar.gz: ecc75dfcdedebc1c45002b810aca77bbc718f88d
3
+ metadata.gz: 625b48150e412a619902ea30d6e81a75064e3677
4
+ data.tar.gz: 1040e0def73820f0b2370fd711291bfa296162e6
5
5
  SHA512:
6
- metadata.gz: a43f9d75ba1b13b46b61f4c73dec7e8cf0bfa88577d7d7a2c82727f186349ef9c97bde0f48d8ad1d1e66e32ea007b43583a8dfd8ee7301e154cead7001d01fe3
7
- data.tar.gz: a64132ec3f39e863164bfa19d1409e524362a78f63486322f04f7bba635c41c799a0b7ace927ecd5dda7e7bbaa03ff76eb4aeff7b824fc2f7652a909f7b9219e
6
+ metadata.gz: 0e1d167dbed5e91f1681a0e704a4df687c53d59edfa9b659ea618f58b7e89c8a3fb406fdbddaf9748562b04f853629ed22da46bfb143f5027911640333196b11
7
+ data.tar.gz: 80a7130d24b8a42e0cd43e0c2ac205fbeae8bd6190ad9700d6165e75a05e90aa859b4128400cbb773ff375b1c298f8f3091806e7f150b540ebee29549ec4cea5
@@ -57,36 +57,32 @@ module Curryer
57
57
  reset_cache!
58
58
  end
59
59
 
60
- def __get_obj__
60
+ def __getobj__
61
61
  @target
62
62
  end
63
63
 
64
- def __set_obj__(new_target)
64
+ def __setobj__(new_target)
65
65
  reset_cache!
66
66
  @target = new_target
67
67
  end
68
68
 
69
69
  # See STLIB's delegate.rb. This is mostly just an adaption of what the
70
70
  # base Delegate#method_missing is doing.
71
- def method_missing(m, *local_args, &b)
72
- target = self.__get_obj__
71
+ def method_missing(m, *local_args, &blk)
72
+ target = self.__getobj__
73
73
 
74
74
  # Get the method, and put a partially-evaluated version of it in the cache
75
75
  # so that we don't have to re-curry future calls. Then call it with the
76
76
  # local args.
77
77
  if target.respond_to?(m)
78
- result = @cache[m] ||= target.method(m).to_proc.curry[*@args]
79
- if local_args.empty?
80
- result
81
- else
82
- if result.respond_to?(:call)
83
- result.call(*local_args)
84
- else
85
- raise ArgumentError, \
86
- "Curried result #{result.inspect} is not callable but arguments #{local_args} were still given. " +
87
- "You're trying to call the method with more arguments than it takes."
88
- end
89
- end
78
+ # Only once, make a closure for the method that applies the saved args
79
+ # to the method.
80
+ #
81
+ # Originally used Proc#curry, but doesn't work with certain
82
+ # metaprogramming styles that don't allow you to grab the metaprogrammed
83
+ # method.
84
+ result = @cache[m] ||= ->(*las, &b) { target.send(m, *(@args + las), &b) }
85
+ result.call(*local_args, &blk)
90
86
  else
91
87
  super(m, *local_args, &b)
92
88
  end
@@ -1,3 +1,3 @@
1
1
  module Curryer
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: curryer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew O'Brien