guessmethod 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,8 +1,5 @@
1
- == 0.0.4 2007-07-18
1
+ == 0.0.5 2007-07-18
2
2
 
3
- * a few minor bits:
4
- * renamed GuessMethodClassMethods to the more correct GuessConstant
5
- * changed the gem description in the Rakefile
6
- * moved const_missing aliasing to GuessConstant
7
- * tweaked the readme
8
- * auto included GuessMethod into Object
3
+ * a little thing
4
+ * capped the longest object.inspect that will show
5
+ * added an option :active to GuessMethod::Options, so you can turn it off if need be
data/README.txt CHANGED
@@ -14,10 +14,12 @@ If you accidentally try to access <tt>File::RDWr</tt>, you'll get <tt>File::RDWR
14
14
 
15
15
  == Options
16
16
 
17
- <tt>GuessMethod::Options</tt> is a hash with configuration values. The keys :insert_weight,
18
- :delete_weight, and :substitution_weight change the behavior of the levenshtein calculation.
19
- :threshold determines how close a method or constant name needs to be to be counted as a 'match'.
20
- Values over 2 can give you unpredictable results, especially for short names.
17
+ <tt>GuessMethod::Options</tt> is a hash with configuration values.
18
+
19
+ * <code>GuessMethod::Options[:insert_weight]</code>, <code>GuessMethod::Options[:delete_weight]</code>, and <code>GuessMethod::Options[:substitution_weight]</code> change how the levenshtein distance is calculated between method and constant names. The default values are all 1.
20
+ * <code>GuessMethod::Options[:threshold]</code> determines what levenshtein distance a method or constant must be within to count as a possible match. Values over 2 can give you unpredictable results, especially for short names. The default value is 2.
21
+ * <code>GuessMethod::Options[:max_inspect_length]</code> is, for now, the longest an object's inspect value can be before it's not displayed in messages, and is replaced with simply the standard #<Object:0x91842923>. The default value is 25.
22
+ * <code>GuessMethod::Options[:active]</code> determines whether or not GuessMethod does its thing. If set to false (or nil) it'll step aside. Useful for when it gets in the way of something going off correctly (which happens sometimes).
21
23
 
22
24
  = Warning
23
25
 
data/lib/guessmethod.rb CHANGED
@@ -14,7 +14,9 @@ module GuessMethod
14
14
  :insert_weight => 1,
15
15
  :delete_weight => 1,
16
16
  :substitution_weight => 1,
17
- :threshold => 2
17
+ :threshold => 2,
18
+ :max_inspect_length => 25,
19
+ :active => true
18
20
  }
19
21
 
20
22
  def self.included(base)
@@ -30,17 +32,21 @@ module GuessMethod
30
32
  end
31
33
 
32
34
  def guess_method_missing(meth, *args, &block)
33
- possible_methods = Guesser.find_closest(self.methods, meth)
34
- case possible_methods.size
35
- when 1
36
- call_method = possible_methods.first
37
- $stderr.puts Outputter.replacing_method(meth, call_method, self)
38
- self.send(call_method, *args, &block)
39
- when 0
40
- $stderr.puts Outputter.no_method_in_threshold(meth, self)
41
- old_method_missing(meth, *args, &block)
35
+ if Options[:active]
36
+ possible_methods = Guesser.find_closest(self.methods, meth)
37
+ case possible_methods.size
38
+ when 1
39
+ call_method = possible_methods.first
40
+ $stderr.puts Outputter.replacing_method(meth, call_method, self)
41
+ self.send(call_method, *args, &block)
42
+ when 0
43
+ $stderr.puts Outputter.no_method_in_threshold(meth, self)
44
+ old_method_missing(meth, *args, &block)
45
+ else
46
+ $stderr.puts Outputter.ambiguous_method(meth, possible_methods, self)
47
+ old_method_missing(meth, *args, &block)
48
+ end
42
49
  else
43
- $stderr.puts Outputter.ambiguous_method(meth, possible_methods, self)
44
50
  old_method_missing(meth, *args, &block)
45
51
  end
46
52
  end
@@ -69,9 +75,14 @@ module GuessMethod
69
75
  Formatter = HighLine.new
70
76
 
71
77
  def self.object(obj) #:nodoc:
72
- message = Formatter.color(obj.inspect, :green, :bold)
73
- message << ':'
74
- message << Formatter.color(obj.class, :green)
78
+ inspected = obj.inspect
79
+ if obj.inspect.length > Options[:max_inspect_length]
80
+ Formatter.color("#<#{obj.class}:0x#{(obj.object_id*2).to_s(16)}>", :green)
81
+ else
82
+ message = Formatter.color(obj.inspect, :green, :bold)
83
+ message << ':'
84
+ message << Formatter.color(obj.class, :green)
85
+ end
75
86
  end
76
87
 
77
88
  def self.ambiguous_method(meth, possibilities, obj) #:nodoc:
@@ -2,7 +2,7 @@ module GuessMethod #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 4
5
+ TINY = 5
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/website/index.html CHANGED
@@ -33,7 +33,7 @@
33
33
  <h1>Guess Method</h1>
34
34
  <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/guessmethod"; return false'>
35
35
  <p>Get Version</p>
36
- <a href="http://rubyforge.org/projects/guessmethod" class="numbers">0.0.4</a>
36
+ <a href="http://rubyforge.org/projects/guessmethod" class="numbers">0.0.5</a>
37
37
  </div>
38
38
  <h1>&#x2192; &#8216;guessmethod&#8217;</h1>
39
39
 
@@ -65,27 +65,34 @@ const_missing handle the problem.</p>
65
65
  <h2>Demonstration of usage</h2>
66
66
 
67
67
 
68
- <pre>mvb:~ cms$ irb
69
- 001:0&gt; require 'guessmethod'
68
+ <pre>001:0&gt; require 'rubygems'
70
69
  true
71
- 002:0&gt; Stirng.tos
70
+ 002:0&gt; require 'guessmethod'
71
+ true
72
+ 003:0&gt; Stirng.tos
72
73
  attention: replacing non-existant constant Stirng with String for Object
73
74
  attention: sending to_s instead of tos to String:Class
74
75
  "String"
75
- 003:0&gt; ['1','2','3'].mp {|x| x.to_}
76
+ 004:0&gt; ['1','2','3'].mp {|x| x.tof}
76
77
  attention: sending map instead of mp to ["1", "2", "3"]:Array
77
- ambigious method: to_ possible matches to_a, to_i, to_s, to_f for "1":String
78
- NoMethodError: undefined method `to_' for "1":String
79
- from /usr/local/lib/ruby/gems/1.8/gems/guessmethod-0.0.3/lib/guessmethod.rb:23:in `old_method_missing'
80
- from /usr/local/lib/ruby/gems/1.8/gems/guessmethod-0.0.3/lib/guessmethod.rb:50:in `method_missing'
81
- from (irb):3
82
- from /usr/local/lib/ruby/gems/1.8/gems/guessmethod-0.0.3/lib/guessmethod.rb:44:in `map'
83
- from /usr/local/lib/ruby/gems/1.8/gems/guessmethod-0.0.3/lib/guessmethod.rb:44:in `send'
84
- from /usr/local/lib/ruby/gems/1.8/gems/guessmethod-0.0.3/lib/guessmethod.rb:44:in `method_missing'
85
- from (irb):3
86
- 004:0&gt; eixt
78
+ attention: sending to_f instead of tof to "1":String
79
+ attention: sending to_f instead of tof to "2":String
80
+ attention: sending to_f instead of tof to "3":String
81
+ [1.0, 2.0, 3.0]
82
+ 005:0&gt; eixt
87
83
  attention: sending exit instead of eixt to main:Object
88
- mvb:~ cms$</pre>
84
+ </pre>
85
+
86
+ <p>There are a number of options available which affect how GuessMethod works.</p>
87
+
88
+
89
+ <ul>
90
+ <li><code>GuessMethod::Options[:insert_weight]</code>, <code>GuessMethod::Options[:delete_weight]</code>, <code>GuessMethod::Options[:substitution_weight]</code> change how the levenshtein distance is calculated between method and constant names. The default values are all 1.</li>
91
+ <li><code>GuessMethod::Options[:threshold]</code> determines what levenshtein distance a method or constant must be within to count as a possible match. Values over 2 can give you unpredictable results, especially for short names. The default value is 2.</li>
92
+ <li><code>GuessMethod::Options[:max_inspect_length]</code> is, for now, the longest an object&#8217;s inspect value can be before it&#8217;s not displayed in messages, and is replaced with simply the standard #<Object:0x91842923>. The default value is 25.</li>
93
+ <li><code>GuessMethod::Options[:active]</code> determines whether or not GuessMethod does its thing. If set to false (or nil) it&#8217;ll step aside. Useful for when it gets in the way of something going off correctly (which happens sometimes).</li>
94
+ </ul>
95
+
89
96
 
90
97
  <h2>How to submit patches</h2>
91
98
 
@@ -110,7 +117,7 @@ mvb:~ cms$</pre>
110
117
 
111
118
  <p>Comments are welcome. Send an email to chris @@ tie-rack .. org.</p>
112
119
  <p class="coda">
113
- website generated via <a href="mailto:drnicwilliams@gmail.com">Dr Nic</a>'s <a href="http://newgem.rubyforge.org/">newgem</a>, on 23rd July 2007<br>
120
+ website generated via <a href="mailto:drnicwilliams@gmail.com">Dr Nic</a>'s <a href="http://newgem.rubyforge.org/">newgem</a>, on 26th July 2007<br>
114
121
  Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
115
122
  </p>
116
123
  </div>
data/website/index.txt CHANGED
@@ -23,27 +23,30 @@ h2. Installing
23
23
 
24
24
  h2. Demonstration of usage
25
25
 
26
- <pre>mvb:~ cms$ irb
27
- 001:0> require 'guessmethod'
26
+ <pre>001:0> require 'rubygems'
28
27
  true
29
- 002:0> Stirng.tos
28
+ 002:0> require 'guessmethod'
29
+ true
30
+ 003:0> Stirng.tos
30
31
  attention: replacing non-existant constant Stirng with String for Object
31
32
  attention: sending to_s instead of tos to String:Class
32
33
  "String"
33
- 003:0> ['1','2','3'].mp {|x| x.to_}
34
+ 004:0> ['1','2','3'].mp {|x| x.tof}
34
35
  attention: sending map instead of mp to ["1", "2", "3"]:Array
35
- ambigious method: to_ possible matches to_a, to_i, to_s, to_f for "1":String
36
- NoMethodError: undefined method `to_' for "1":String
37
- from /usr/local/lib/ruby/gems/1.8/gems/guessmethod-0.0.3/lib/guessmethod.rb:23:in `old_method_missing'
38
- from /usr/local/lib/ruby/gems/1.8/gems/guessmethod-0.0.3/lib/guessmethod.rb:50:in `method_missing'
39
- from (irb):3
40
- from /usr/local/lib/ruby/gems/1.8/gems/guessmethod-0.0.3/lib/guessmethod.rb:44:in `map'
41
- from /usr/local/lib/ruby/gems/1.8/gems/guessmethod-0.0.3/lib/guessmethod.rb:44:in `send'
42
- from /usr/local/lib/ruby/gems/1.8/gems/guessmethod-0.0.3/lib/guessmethod.rb:44:in `method_missing'
43
- from (irb):3
44
- 004:0> eixt
36
+ attention: sending to_f instead of tof to "1":String
37
+ attention: sending to_f instead of tof to "2":String
38
+ attention: sending to_f instead of tof to "3":String
39
+ [1.0, 2.0, 3.0]
40
+ 005:0> eixt
45
41
  attention: sending exit instead of eixt to main:Object
46
- mvb:~ cms$</pre>
42
+ </pre>
43
+
44
+ There are a number of options available which affect how GuessMethod works.
45
+
46
+ * <code>GuessMethod::Options[:insert_weight]</code>, <code>GuessMethod::Options[:delete_weight]</code>, <code>GuessMethod::Options[:substitution_weight]</code> change how the levenshtein distance is calculated between method and constant names. The default values are all 1.
47
+ * <code>GuessMethod::Options[:threshold]</code> determines what levenshtein distance a method or constant must be within to count as a possible match. Values over 2 can give you unpredictable results, especially for short names. The default value is 2.
48
+ * <code>GuessMethod::Options[:max_inspect_length]</code> is, for now, the longest an object's inspect value can be before it's not displayed in messages, and is replaced with simply the standard #<Object:0x91842923>. The default value is 25.
49
+ * <code>GuessMethod::Options[:active]</code> determines whether or not GuessMethod does its thing. If set to false (or nil) it'll step aside. Useful for when it gets in the way of something going off correctly (which happens sometimes).
47
50
 
48
51
  h2. How to submit patches
49
52
 
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: guessmethod
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.4
7
- date: 2007-07-23 00:00:00 -06:00
6
+ version: 0.0.5
7
+ date: 2007-07-26 00:00:00 -06:00
8
8
  summary: an aggressive spell checker for irb
9
9
  require_paths:
10
10
  - lib