close_enough 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/close_enough.rb CHANGED
@@ -6,8 +6,13 @@ class Object
6
6
  def method_missing(name, *args)
7
7
  dl = DamerauLevenshtein
8
8
  ms = methods.map(&:to_s).freeze
9
- meth = meth = ms.select {|a| dl.distance(name.to_s, a) < 3}.first
10
9
 
11
- meth ? send(meth, *args) : super
10
+ meth = ms.inject([]) do |matches, a|
11
+ distance = dl.distance(name.to_s, a)
12
+ matches << [distance, a] if distance < 3
13
+ matches
14
+ end.sort_by(&:first).first
15
+
16
+ meth ? send(meth[1], *args) : super
12
17
  end
13
- end
18
+ end
@@ -33,6 +33,11 @@ module CloseEnoughSpec
33
33
  end
34
34
  end
35
35
 
36
+ describe "it should call the closest method, out of all methods < 3 away" do
36
37
 
38
+ it "should find to_sym when to_sim is called (instead of to_str)" do
39
+ 'contrived'.to_sim.should == :contrived
40
+ end
41
+ end
37
42
 
38
- end
43
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: close_enough
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-03-01 00:00:00.000000000 Z
13
+ date: 2013-03-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: damerau-levenshtein
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  version: '0'
95
95
  requirements: []
96
96
  rubyforge_project:
97
- rubygems_version: 1.8.24
97
+ rubygems_version: 1.8.25
98
98
  signing_key:
99
99
  specification_version: 3
100
100
  summary: Mistyping methods? Not a problem.