ori 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.html +158 -0
- data/README.md +160 -0
- data/Rakefile +60 -0
- data/VERSION.yml +5 -0
- data/lib/misc/method_aliases.rb +11 -0
- data/lib/ori.rb +47 -0
- data/lib/ori/auto_config.rb +78 -0
- data/lib/ori/colorize.rb +62 -0
- data/lib/ori/config.rb +27 -0
- data/lib/ori/extensions.rb +4 -0
- data/lib/ori/extensions/object/ri.rb +88 -0
- data/lib/ori/internals.rb +411 -0
- data/lib/ori/library.rb +59 -0
- data/lib/ori/list_method.rb +247 -0
- data/lib/ori/request.rb +118 -0
- data/lib/ori/tools.rb +142 -0
- data/ori.gemspec +82 -0
- data/samples/NOTES +3 -0
- data/samples/basic_extension.rb +27 -0
- data/samples/basic_inheritance.rb +99 -0
- data/samples/self_singletons.rb +36 -0
- data/samples/singleton_class_includes_module.rb +33 -0
- data/spec/auto_config_spec.rb +33 -0
- data/spec/colorize_spec.rb +26 -0
- data/spec/inspector_spec.rb +75 -0
- data/spec/internals_spec.rb +219 -0
- data/spec/list_method_spec.rb +118 -0
- data/spec/request_spec.rb +72 -0
- data/spec/site/NOTES +3 -0
- data/spec/site/library_spec.rb +33 -0
- data/spec/site/spec_helper.rb +1 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/tools_spec.rb +109 -0
- metadata +107 -0
data/ori.gemspec
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{ori}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Alex Fortuna"]
|
12
|
+
s.date = %q{2011-01-02}
|
13
|
+
s.description = %q{Object-Oriented RI for IRB Console}
|
14
|
+
s.email = %q{alex.r@askit.org}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.html",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
"MIT-LICENSE",
|
21
|
+
"README.html",
|
22
|
+
"README.md",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION.yml",
|
25
|
+
"lib/misc/method_aliases.rb",
|
26
|
+
"lib/ori.rb",
|
27
|
+
"lib/ori/auto_config.rb",
|
28
|
+
"lib/ori/colorize.rb",
|
29
|
+
"lib/ori/config.rb",
|
30
|
+
"lib/ori/extensions.rb",
|
31
|
+
"lib/ori/extensions/object/ri.rb",
|
32
|
+
"lib/ori/internals.rb",
|
33
|
+
"lib/ori/library.rb",
|
34
|
+
"lib/ori/list_method.rb",
|
35
|
+
"lib/ori/request.rb",
|
36
|
+
"lib/ori/tools.rb",
|
37
|
+
"ori.gemspec",
|
38
|
+
"samples/NOTES",
|
39
|
+
"samples/basic_extension.rb",
|
40
|
+
"samples/basic_inheritance.rb",
|
41
|
+
"samples/self_singletons.rb",
|
42
|
+
"samples/singleton_class_includes_module.rb",
|
43
|
+
"spec/auto_config_spec.rb",
|
44
|
+
"spec/colorize_spec.rb",
|
45
|
+
"spec/inspector_spec.rb",
|
46
|
+
"spec/internals_spec.rb",
|
47
|
+
"spec/list_method_spec.rb",
|
48
|
+
"spec/request_spec.rb",
|
49
|
+
"spec/site/NOTES",
|
50
|
+
"spec/site/library_spec.rb",
|
51
|
+
"spec/site/spec_helper.rb",
|
52
|
+
"spec/spec_helper.rb",
|
53
|
+
"spec/tools_spec.rb"
|
54
|
+
]
|
55
|
+
s.homepage = %q{http://github.com/dadooda/ori}
|
56
|
+
s.require_paths = ["lib"]
|
57
|
+
s.rubygems_version = %q{1.3.7}
|
58
|
+
s.summary = %q{Object-Oriented RI for IRB Console}
|
59
|
+
s.test_files = [
|
60
|
+
"spec/auto_config_spec.rb",
|
61
|
+
"spec/colorize_spec.rb",
|
62
|
+
"spec/inspector_spec.rb",
|
63
|
+
"spec/internals_spec.rb",
|
64
|
+
"spec/list_method_spec.rb",
|
65
|
+
"spec/request_spec.rb",
|
66
|
+
"spec/site/library_spec.rb",
|
67
|
+
"spec/site/spec_helper.rb",
|
68
|
+
"spec/spec_helper.rb",
|
69
|
+
"spec/tools_spec.rb"
|
70
|
+
]
|
71
|
+
|
72
|
+
if s.respond_to? :specification_version then
|
73
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
74
|
+
s.specification_version = 3
|
75
|
+
|
76
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
77
|
+
else
|
78
|
+
end
|
79
|
+
else
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
data/samples/NOTES
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Sample
|
2
|
+
module BasicExtension
|
3
|
+
module Mo
|
4
|
+
def public_meth
|
5
|
+
true
|
6
|
+
end
|
7
|
+
|
8
|
+
protected
|
9
|
+
def protected_meth
|
10
|
+
true
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def private_meth
|
15
|
+
true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Klass
|
20
|
+
extend Mo
|
21
|
+
end
|
22
|
+
|
23
|
+
module OtherMo
|
24
|
+
extend Mo
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
module Sample
|
2
|
+
module BasicInheritance
|
3
|
+
class Grandpa
|
4
|
+
def grandpa_public
|
5
|
+
true
|
6
|
+
end
|
7
|
+
|
8
|
+
protected
|
9
|
+
def grandpa_protected
|
10
|
+
true
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def grandpa_private
|
15
|
+
true
|
16
|
+
end
|
17
|
+
|
18
|
+
class << self
|
19
|
+
def grandpa_public_singleton
|
20
|
+
true
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
def grandpa_protected_singleton
|
25
|
+
true
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def grandpa_private_singleton
|
30
|
+
true
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end # Grandpa
|
34
|
+
|
35
|
+
class Papa < Grandpa
|
36
|
+
def papa_public
|
37
|
+
true
|
38
|
+
end
|
39
|
+
|
40
|
+
protected
|
41
|
+
def papa_protected
|
42
|
+
true
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
def papa_private
|
47
|
+
true
|
48
|
+
end
|
49
|
+
|
50
|
+
class << self
|
51
|
+
def papa_public_singleton
|
52
|
+
true
|
53
|
+
end
|
54
|
+
|
55
|
+
protected
|
56
|
+
def papa_protected_singleton
|
57
|
+
true
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
def papa_private_singleton
|
62
|
+
true
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end # Papa
|
66
|
+
|
67
|
+
class Son < Papa
|
68
|
+
def son_public
|
69
|
+
true
|
70
|
+
end
|
71
|
+
|
72
|
+
protected
|
73
|
+
def son_protected
|
74
|
+
true
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
def son_private
|
79
|
+
true
|
80
|
+
end
|
81
|
+
|
82
|
+
class << self
|
83
|
+
def son_public_singleton
|
84
|
+
true
|
85
|
+
end
|
86
|
+
|
87
|
+
protected
|
88
|
+
def son_protected_singleton
|
89
|
+
true
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
def son_private_singleton
|
94
|
+
true
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end # Son
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Sample
|
2
|
+
# Singletons declared via <tt>self.</tt> are in fact always public.
|
3
|
+
module SelfSingletons
|
4
|
+
module Mo
|
5
|
+
def self.public_meth
|
6
|
+
true
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
def self.protected_meth
|
11
|
+
true
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
def self.private_meth
|
16
|
+
true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class Klass
|
21
|
+
def self.public_meth
|
22
|
+
true
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
def self.protected_meth
|
27
|
+
true
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def self.private_meth
|
32
|
+
true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Sample
|
2
|
+
module SingletonClassIncludesModule
|
3
|
+
module Mo
|
4
|
+
# NOTE: Method names are in context of `Mo`. `Mo` doesn't "know" that they are to become singleton.
|
5
|
+
|
6
|
+
def public_meth
|
7
|
+
true
|
8
|
+
end
|
9
|
+
|
10
|
+
protected
|
11
|
+
def protected_meth
|
12
|
+
true
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def private_meth
|
17
|
+
true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class Klass
|
22
|
+
class << self
|
23
|
+
include Mo
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
module OtherMo
|
28
|
+
class << self
|
29
|
+
include Mo
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
+
|
3
|
+
describe "::ORI::AutoConfig" do
|
4
|
+
klass = ::ORI::AutoConfig
|
5
|
+
|
6
|
+
it "requires host_os most of the time" do
|
7
|
+
r = klass.new
|
8
|
+
proc {r.has_less?}.should raise_error
|
9
|
+
proc {r.unix?}.should raise_error
|
10
|
+
proc {r.windows?}.should raise_error
|
11
|
+
|
12
|
+
proc {r.color}.should raise_error
|
13
|
+
proc {r.frontend}.should raise_error
|
14
|
+
proc {r.pager}.should raise_error
|
15
|
+
proc {r.shell_escape}.should raise_error
|
16
|
+
end
|
17
|
+
|
18
|
+
it "generally works" do
|
19
|
+
r = klass.new(:host_os => "mswin32")
|
20
|
+
r.has_less?.should == false
|
21
|
+
r.unix?.should == false
|
22
|
+
r.windows?.should == true
|
23
|
+
|
24
|
+
r = klass.new(:host_os => "cygwin")
|
25
|
+
r.has_less?.should == true
|
26
|
+
r.color.should == true
|
27
|
+
|
28
|
+
r = klass.new(:host_os => "linux-gnu")
|
29
|
+
r.has_less?.should == true
|
30
|
+
r.color.should == true
|
31
|
+
r.frontend.should match /ansi/
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
+
|
3
|
+
describe "::ORI::Tools" do
|
4
|
+
mod = ::ORI::Colorize
|
5
|
+
|
6
|
+
describe ".colorize" do
|
7
|
+
meth = :colorize
|
8
|
+
|
9
|
+
it "generally works" do
|
10
|
+
mod.send(meth, "the quick ", "brown fox").should == "the quick brown fox"
|
11
|
+
mod.send(meth, [:message, :error], "the message", [:reset]).should(match(/the message/) && match(/\e\[0m/)) # NOTE: () and && are to satisfy Ruby 1.8.
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe ".seq" do
|
16
|
+
meth = :seq
|
17
|
+
|
18
|
+
it "generally works" do
|
19
|
+
mod.send(meth, :reset).should == "\e[0m"
|
20
|
+
|
21
|
+
proc do
|
22
|
+
mod.send(meth, :kaka)
|
23
|
+
end.should raise_error ArgumentError
|
24
|
+
end
|
25
|
+
end # .seq
|
26
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
+
|
3
|
+
# Rules of method inspection, formulated as spec samples.
|
4
|
+
#
|
5
|
+
# NOTES:
|
6
|
+
# * DO NOT sort arrays to compare them with each other. Instead use array arithmetic.
|
7
|
+
# * Try NOT to touch method `methods`. ORI doesn't actually use it.
|
8
|
+
# * Test concrete inspectors thoroughly: `public_methods`, `protected_methods`, etc.
|
9
|
+
# * Sort from more public to less public: public -- protected -- private.
|
10
|
+
|
11
|
+
obj_subjects = [
|
12
|
+
nil,
|
13
|
+
false,
|
14
|
+
5,
|
15
|
+
"kaka",
|
16
|
+
Time.now,
|
17
|
+
]
|
18
|
+
|
19
|
+
class_subjects = [
|
20
|
+
Array,
|
21
|
+
Fixnum,
|
22
|
+
String,
|
23
|
+
]
|
24
|
+
|
25
|
+
module_subjects = [
|
26
|
+
Enumerable,
|
27
|
+
Kernel,
|
28
|
+
]
|
29
|
+
|
30
|
+
cm_subjects = class_subjects + module_subjects
|
31
|
+
all_subjects = obj_subjects + cm_subjects
|
32
|
+
|
33
|
+
describe "{Class|Module}#instance_methods" do
|
34
|
+
it "does not intersect #private_instance_methods" do
|
35
|
+
(cm_subjects).each do |subj|
|
36
|
+
(subj.instance_methods & subj.private_instance_methods).should == []
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it "is fully contained in (#public_instance_methods + #protected_instance_methods)" do
|
41
|
+
(cm_subjects).each do |subj|
|
42
|
+
(subj.instance_methods - (subj.public_instance_methods + subj.protected_instance_methods)).should == []
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "anything#methods" do
|
48
|
+
it "is fully contained in (#public_methods + #protected_methods)" do
|
49
|
+
all_subjects.each do |subj|
|
50
|
+
(subj.methods - (subj.public_methods + subj.protected_methods)).should == []
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "{Class|Module}#singleton_methods" do
|
56
|
+
it "is fully contained in (#public_methods + #protected_methods + #private_methods)" do
|
57
|
+
cm_subjects.each do |subj|
|
58
|
+
(subj.singleton_methods - (subj.public_methods + subj.protected_methods + subj.private_methods)).should == []
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "Module#singleton_methods" do
|
64
|
+
it "is fully containted in #public_methods" do
|
65
|
+
module_subjects.each do |subj|
|
66
|
+
(subj.singleton_methods - subj.public_methods).should == []
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
it "does not intersect with #protected_methods or #private_methods)" do
|
71
|
+
module_subjects.each do |subj|
|
72
|
+
(subj.singleton_methods & (subj.protected_methods + subj.private_methods)).should == []
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,219 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
+
|
3
|
+
# NOTE: When checking collection against the rule, it's wiser to use `all?`, `any?` and `none?` and ONE `should` at the end. It's about 2 times faster
|
4
|
+
# than calling a `should` at every pass of an `each` loop.
|
5
|
+
|
6
|
+
describe "::ORI::Internals" do
|
7
|
+
mod = ::ORI::Internals
|
8
|
+
|
9
|
+
describe ".get_list_methods" do
|
10
|
+
meth = :get_list_methods
|
11
|
+
|
12
|
+
it "maintains uniqueness of output" do
|
13
|
+
list1 = mod.send(meth, :objs => [1])
|
14
|
+
list2 = mod.send(meth, :objs => [1, 1])
|
15
|
+
(list2 - list1).should be_empty
|
16
|
+
|
17
|
+
list1 = mod.send(meth, :objs => [Array])
|
18
|
+
list2 = mod.send(meth, :objs => [Array, Array])
|
19
|
+
(list2 - list1).should be_empty
|
20
|
+
|
21
|
+
list1 = mod.send(meth, :objs => [1])
|
22
|
+
list2 = mod.send(meth, :objs => [1, 2])
|
23
|
+
(list2 - list1).should be_empty
|
24
|
+
end
|
25
|
+
|
26
|
+
it "requires :objs option to be an Array" do
|
27
|
+
proc do
|
28
|
+
mod.send(meth)
|
29
|
+
end.should raise_error ArgumentError
|
30
|
+
|
31
|
+
proc do
|
32
|
+
mod.send(meth, :objs => 5)
|
33
|
+
end.should raise_error ArgumentError
|
34
|
+
end
|
35
|
+
|
36
|
+
it "supports :access option" do
|
37
|
+
proc do
|
38
|
+
mod.send(meth, :objs => [5], :access => 1)
|
39
|
+
mod.send(meth, :objs => [5], :access => "kk")
|
40
|
+
end.should raise_error ArgumentError
|
41
|
+
|
42
|
+
proc do
|
43
|
+
mod.send(meth, :objs => [5], :access => "#")
|
44
|
+
mod.send(meth, :objs => [5], :access => "::")
|
45
|
+
mod.send(meth, :objs => [5], :access => :"#")
|
46
|
+
mod.send(meth, :objs => [5], :access => :"::")
|
47
|
+
end.should_not raise_error
|
48
|
+
|
49
|
+
list_methods = mod.send(meth, :objs => [Time], :access => "::")
|
50
|
+
list_methods.all? {|r| r.access == "::"}.should == true
|
51
|
+
|
52
|
+
list_methods = mod.send(meth, :objs => [Time], :access => "#")
|
53
|
+
list_methods.all? {|r| r.access == "#"}.should == true
|
54
|
+
end
|
55
|
+
|
56
|
+
it "supports `:fullre` option" do
|
57
|
+
list_methods = mod.send(meth, :objs => [Module], :fullre => (re = /Object.*::/))
|
58
|
+
##re = /kk/ #DEBUG: Fail by hand.
|
59
|
+
list_methods.all? do |r|
|
60
|
+
##p "r", r
|
61
|
+
r.format(:color => false).match re
|
62
|
+
end.should == true
|
63
|
+
end
|
64
|
+
|
65
|
+
it "supports `:own` option" do
|
66
|
+
inputs = []
|
67
|
+
inputs << 5
|
68
|
+
inputs << []
|
69
|
+
inputs << String
|
70
|
+
inputs << Enumerable
|
71
|
+
inputs << Array
|
72
|
+
inputs << Class
|
73
|
+
inputs << Module
|
74
|
+
inputs << Object
|
75
|
+
|
76
|
+
inputs.each do |obj|
|
77
|
+
list_methods = mod.send(meth, :objs => [obj], :own => true)
|
78
|
+
list_methods.all? do |r|
|
79
|
+
##p "r", r # Uncomment if fails.
|
80
|
+
r.own?
|
81
|
+
end.should == true
|
82
|
+
end
|
83
|
+
|
84
|
+
list_methods = mod.send(meth, :objs => inputs, :own => true)
|
85
|
+
list_methods.all? do |r|
|
86
|
+
##p "r", r # Uncomment if fails.
|
87
|
+
r.own?
|
88
|
+
end.should == true
|
89
|
+
end
|
90
|
+
|
91
|
+
it "supports `:re` option" do
|
92
|
+
list_methods = mod.send(meth, :objs => [Module], :re => (re = /pub/))
|
93
|
+
##re = /kk/ #DEBUG: Fail by hand.
|
94
|
+
list_methods.all? do |r|
|
95
|
+
##p "r", r
|
96
|
+
r.method_name.match re
|
97
|
+
end.should == true
|
98
|
+
end
|
99
|
+
|
100
|
+
it "supports `:visibility` option" do
|
101
|
+
list_methods = mod.send(meth, :objs => [::Sample::BasicInheritance::Son], :all => true, :visibility => :public)
|
102
|
+
list_methods.all? do |r|
|
103
|
+
##p "r", r
|
104
|
+
r.public?
|
105
|
+
end.should == true
|
106
|
+
|
107
|
+
list_methods = mod.send(meth, :objs => [::Sample::BasicInheritance::Son], :all => true, :visibility => :protected)
|
108
|
+
list_methods.all? do |r|
|
109
|
+
##p "r", r
|
110
|
+
r.protected?
|
111
|
+
end.should == true
|
112
|
+
|
113
|
+
list_methods = mod.send(meth, :objs => [::Sample::BasicInheritance::Son], :all => true, :visibility => :private)
|
114
|
+
list_methods.all? do |r|
|
115
|
+
##p "r", r
|
116
|
+
r.private?
|
117
|
+
end.should == true
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "filtering" do
|
121
|
+
it "chops off all methods starting with '_ori_'" do
|
122
|
+
inputs = [5, "", [], String, Enumerable, Array, Class, Module, Object]
|
123
|
+
inputs.each do |obj|
|
124
|
+
list_methods = mod.send(meth, :objs => [obj])
|
125
|
+
list_methods.none? do |r|
|
126
|
+
##p "r", r # Uncomment if fails.
|
127
|
+
r.method_name.match /\A_ori_/
|
128
|
+
end.should == true
|
129
|
+
end
|
130
|
+
|
131
|
+
list_methods = mod.send(meth, :objs => inputs)
|
132
|
+
list_methods.none? do |r|
|
133
|
+
##p "r", r # Uncomment if fails.
|
134
|
+
r.method_name.match /\A_ori_/
|
135
|
+
end.should == true
|
136
|
+
end
|
137
|
+
|
138
|
+
it "chops off non-public Kernel methods if `obj` is not Kernel" do
|
139
|
+
inputs = [5, "", [], String, Enumerable, Array, Class, Module, Object]
|
140
|
+
inputs.each do |obj|
|
141
|
+
list_methods = mod.send(meth, :objs => [obj])
|
142
|
+
list_methods.none? do |r|
|
143
|
+
##p "r", r # Uncomment if fails.
|
144
|
+
r.owner == Kernel and not r.public?
|
145
|
+
end.should == true
|
146
|
+
|
147
|
+
list_methods = mod.send(meth, :objs => inputs)
|
148
|
+
list_methods.none? do |r|
|
149
|
+
##p "r", r # Uncomment if fails.
|
150
|
+
r.owner == Kernel and not r.public?
|
151
|
+
end.should == true
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
it "chops off non-public methods if `obj` is an object" do
|
156
|
+
inputs = [5, "", []]
|
157
|
+
inputs.each do |obj|
|
158
|
+
list_methods = mod.send(meth, :objs => [obj])
|
159
|
+
list_methods.none? do |r|
|
160
|
+
##p "r", r # Uncomment if fails.
|
161
|
+
not r.public?
|
162
|
+
end.should == true
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
it "chops off others' private instance methods if `obj` is a module or a class" do
|
167
|
+
inputs = [String, Enumerable, Array, Class, Module, Object, ::Sample::BasicInheritance::Son]
|
168
|
+
inputs.each do |obj|
|
169
|
+
list_methods = mod.send(meth, :objs => [obj])
|
170
|
+
list_methods.none? do |r|
|
171
|
+
##p "r", r # Uncomment if fails.
|
172
|
+
not r.own? and r.private? and r.instance?
|
173
|
+
end.should == true
|
174
|
+
end
|
175
|
+
|
176
|
+
list_methods = mod.send(meth, :objs => inputs)
|
177
|
+
list_methods.none? do |r|
|
178
|
+
##p "r", r # Uncomment if fails.
|
179
|
+
not r.own? and r.private? and r.instance?
|
180
|
+
end.should == true
|
181
|
+
end
|
182
|
+
|
183
|
+
it "generally works for modules and classes" do
|
184
|
+
list_methods = mod.send(meth, :objs => [::Sample::BasicInheritance::Son])
|
185
|
+
list_methods.find {|r| r.method_name == "son_public"}.should_not be_nil
|
186
|
+
list_methods.find {|r| r.method_name == "son_protected"}.should_not be_nil
|
187
|
+
list_methods.find {|r| r.method_name == "son_private"}.should_not be_nil
|
188
|
+
list_methods.find {|r| r.method_name == "papa_public"}.should_not be_nil
|
189
|
+
list_methods.find {|r| r.method_name == "papa_protected"}.should_not be_nil
|
190
|
+
list_methods.find {|r| r.method_name == "grandpa_public"}.should_not be_nil
|
191
|
+
list_methods.find {|r| r.method_name == "grandpa_protected"}.should_not be_nil
|
192
|
+
list_methods.find {|r| r.method_name == "papa_private"}.should be_nil
|
193
|
+
list_methods.find {|r| r.method_name == "grandpa_private"}.should be_nil
|
194
|
+
|
195
|
+
list_methods = mod.send(meth, :objs => [::Sample::BasicExtension::Klass])
|
196
|
+
list_methods.find {|r| r.method_name == "public_meth"}.should_not be_nil
|
197
|
+
list_methods.find {|r| r.method_name == "protected_meth"}.should_not be_nil
|
198
|
+
list_methods.find {|r| r.method_name == "private_meth"}.should_not be_nil
|
199
|
+
|
200
|
+
list_methods = mod.send(meth, :objs => [::Sample::BasicExtension::OtherMo])
|
201
|
+
list_methods.find {|r| r.method_name == "public_meth"}.should_not be_nil
|
202
|
+
list_methods.find {|r| r.method_name == "protected_meth"}.should_not be_nil
|
203
|
+
list_methods.find {|r| r.method_name == "private_meth"}.should_not be_nil
|
204
|
+
end
|
205
|
+
end # filtering
|
206
|
+
end # .get_list_methods
|
207
|
+
|
208
|
+
describe ".get_ri_arg_prefix" do
|
209
|
+
meth = :get_ri_arg_prefix
|
210
|
+
|
211
|
+
it "generally works" do
|
212
|
+
mod.send(meth, "kaka").should == nil
|
213
|
+
mod.send(meth, "Object.ri").should == nil
|
214
|
+
mod.send(meth, " Object.ri ").should == nil
|
215
|
+
mod.send(meth, "Object.ri //").should == "Object.ri"
|
216
|
+
mod.send(meth, " Object.ri :x").should == " Object.ri"
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|