method_finder 0.0.1
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.
- data/README +17 -0
- data/lib/method_finder.rb +44 -0
- data/method_finder.gemspec +22 -0
- metadata +56 -0
data/README
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Method_Finder is a clone for the MethodFinder functionality of Smaltalk.
|
2
|
+
|
3
|
+
The results on irb should ilustrate:
|
4
|
+
|
5
|
+
require 'method_finder' #=> true
|
6
|
+
2.match_method([2],4) #=> ["*", "**", "+"]
|
7
|
+
[1].match_method([2],[1,2]) #=> ["<<", "push"]
|
8
|
+
[1].match_method([2,3],[1,2,3]) #=> ["push"]
|
9
|
+
[3,2,1].match_method([],[1,2,3]) #=> ["reverse", "reverse!", "sort", "sort!"]
|
10
|
+
|
11
|
+
Note that default mac ruby and the spec_helper sometimes require 'rubygem', and because of that some tests like the ones bellow broke. This is because tests are poorly made, and when rubygems adds gcd or power! to methods the tests become wrong.
|
12
|
+
|
13
|
+
2.match_method([2],4).should == ['**','*',"+","power!","rpower"].sort
|
14
|
+
5.match_method([4],1).should == ['%','-','/','<=>','div','modulo','remainder','^','gcd'].sort
|
15
|
+
|
16
|
+
There is a gem now, thanks to Pbalduino.
|
17
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
class Object
|
2
|
+
|
3
|
+
def match_method(params,expected, &block)
|
4
|
+
with_warnings_suppressed do
|
5
|
+
methods.select do |method|
|
6
|
+
if method != "match_method"
|
7
|
+
p = params
|
8
|
+
p += ["&block"] if block_given? && method[method.size-1,1] != '='
|
9
|
+
test_method(method, p, expected, &block)
|
10
|
+
end
|
11
|
+
end.sort
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
# Suppresses warnings within a given block.
|
18
|
+
def with_warnings_suppressed
|
19
|
+
saved_verbosity = $-v
|
20
|
+
$-v = nil
|
21
|
+
yield
|
22
|
+
ensure
|
23
|
+
$-v = saved_verbosity
|
24
|
+
end
|
25
|
+
|
26
|
+
def try_clone
|
27
|
+
begin
|
28
|
+
clone
|
29
|
+
rescue
|
30
|
+
self
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_method(method, params, expected, &block)
|
35
|
+
begin
|
36
|
+
clone = try_clone
|
37
|
+
exp = "clone.#{method}(#{params.join(',')})"
|
38
|
+
result = eval(exp)
|
39
|
+
result == expected
|
40
|
+
rescue
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rake/gempackagetask'
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{method_finder}
|
5
|
+
s.version = "0.0.1"
|
6
|
+
s.authors = ["Fabricio Nascimento"]
|
7
|
+
s.date = %q{2009-03-09}
|
8
|
+
s.description = %q{Method_Finder is a clone for the MethodFinder functionality of Smaltalk.}
|
9
|
+
s.email = ["fabriciosn@gmail.com"]
|
10
|
+
s.files = ["method_finder.gemspec","lib/method_finder.rb"]
|
11
|
+
s.require_paths = ["lib"]
|
12
|
+
s.has_rdoc = true
|
13
|
+
s.extra_rdoc_files = ["README"]
|
14
|
+
s.rubygems_version = %q{1.3.1}
|
15
|
+
s.summary = %q{Method_Finder is a clone for the MethodFinder functionality of Smaltalk.}
|
16
|
+
end
|
17
|
+
|
18
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
19
|
+
pkg.need_tar = true
|
20
|
+
pkg.need_zip = true
|
21
|
+
end
|
22
|
+
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: method_finder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Fabricio Nascimento
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-03-09 00:00:00 -03:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Method_Finder is a clone for the MethodFinder functionality of Smaltalk.
|
17
|
+
email:
|
18
|
+
- fabriciosn@gmail.com
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files:
|
24
|
+
- README
|
25
|
+
files:
|
26
|
+
- method_finder.gemspec
|
27
|
+
- lib/method_finder.rb
|
28
|
+
- README
|
29
|
+
has_rdoc: true
|
30
|
+
homepage:
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: "0"
|
41
|
+
version:
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
requirements: []
|
49
|
+
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 1.3.1
|
52
|
+
signing_key:
|
53
|
+
specification_version: 2
|
54
|
+
summary: Method_Finder is a clone for the MethodFinder functionality of Smaltalk.
|
55
|
+
test_files: []
|
56
|
+
|