bornin 3.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/bornin.rb +121 -0
  3. metadata +44 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 511d93d60957de635a1ede71d40b98f4c581a5b4
4
+ data.tar.gz: 2233ca8fe8e8d0208c72077cbc4525fa259c2cc7
5
+ SHA512:
6
+ metadata.gz: f22d12581bbcc054edef9ae5eefe92e0b276bd02323c0bda5f91766c640f4012022cbcde7e75137870dedfbc0d31899c759d4ee59712937e4ceac15d2cbfbd5b
7
+ data.tar.gz: 4688cf9f48b923f2fd0671f7ef9d405c0e310fd91fc5e84eb574ab08ef83c2640b3f6161f23942f8a9fd6faddc83b3e8ae37cfc912b3d6d8e791db301c76475c
@@ -0,0 +1,121 @@
1
+ # Copyright 2013 Naga Vijayapuram
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ #
16
+ # bornin method - spots the class/module where the method was born
17
+ #
18
+ def bornin _method, _class = [
19
+ Fixnum,
20
+ Float,
21
+ String,
22
+ Array,
23
+ Hash,
24
+ Range,
25
+ Regexp,
26
+ Math
27
+ ]
28
+
29
+ # to colorize output
30
+ require 'colorize'
31
+
32
+ # Check
33
+ if _method==nil
34
+ return puts "=> please pass first arg as a string".red
35
+ end
36
+
37
+ # the patten to grep for
38
+ re = Regexp.new '^' + _method.to_s + '$'
39
+
40
+ # born in BasicObject?
41
+ if BasicObject.instance_methods(false).grep(re).size==1
42
+ return puts "=> #{_method} : " +
43
+ ". born in BasicObject as an instance method".green
44
+ # born in Kernel?
45
+ elsif Kernel.instance_methods(false).grep(re).size==1
46
+ return puts "=> #{_method} : " +
47
+ ".. born in Kernel as an instance method".green
48
+ # born in Object?
49
+ elsif Object.instance_methods(false).grep(re).size==1
50
+ return puts "=> #{_method} : " +
51
+ "... born in Object as an instance method".green
52
+ # born in Module?
53
+ elsif Module.instance_methods(false).grep(re).size==1
54
+ return puts "=> #{_method} : " +
55
+ ".... born in Module as an instance method".green
56
+ end
57
+
58
+ # puts "check what class is _class"
59
+ # check what class is _class
60
+ if _class.class == String
61
+ _class = eval(_class)
62
+ elsif _class.class == Symbol
63
+ _class = Kernel.const_get(_class.to_s)
64
+ # relying on some very basic classes listed above when
65
+ # _class was not passed as a param
66
+ elsif _class.is_a? Array
67
+ _class.each do |e|
68
+ # puts "Checking #{_method} in #{e} ..."
69
+ output = bornin2 _method, e
70
+ output || break
71
+ # return
72
+ end
73
+ else
74
+ bornin2 _method, _class
75
+ end
76
+
77
+ end # bornin
78
+
79
+ #
80
+ # bornin2 - scan ancestors
81
+ #
82
+ def bornin2 _method, _class
83
+
84
+ # the patten to grep for
85
+ re = Regexp.new '^' + _method.to_s + '$'
86
+
87
+ _class.ancestors.each do |ancestor|
88
+
89
+ #- in methods?
90
+ if ancestor.methods(false).grep(re).size==1
91
+ return puts "=> #{_method} : " +
92
+ "..... born in #{ancestor} as a method".green
93
+ end
94
+
95
+ #- in instance_methods?
96
+ if ancestor.instance_methods(false).grep(re).size==1
97
+ return puts "=> #{_method} : " +
98
+ "...... born in #{ancestor} as an instance method".green
99
+ end
100
+
101
+ end # scanning ancestors
102
+
103
+ end # bornin2
104
+
105
+ # ------------------------------------
106
+ # Test
107
+ # ------------------------------------
108
+ # bornin 'p'
109
+ # bornin 'puts'
110
+ # bornin 'class_eval'
111
+ # bornin 'module_eval'
112
+ # bornin 'instance_eval'
113
+ # bornin 'join'
114
+ # ------------------------------------
115
+ # bornin 'p', String
116
+ # bornin 'puts', String
117
+ # bornin 'class_eval', String
118
+ # bornin 'module_eval', String
119
+ # bornin 'instance_eval', String
120
+ # bornin 'join', Array
121
+ # ------------------------------------
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bornin
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.5
5
+ platform: ruby
6
+ authors:
7
+ - Naga Vijayapuram
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-27 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: gem to detect where a method was born
14
+ email: nice.ruby.gems@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/bornin.rb
20
+ homepage: https://github.com/nvijayap/bornin
21
+ licenses:
22
+ - Apache v2
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.0.5
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: bornin
44
+ test_files: []