binding_of_callers 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +1 -0
- data/binding_of_callers.gemspec +3 -3
- data/lib/binding_of_callers/reveal.rb +52 -12
- data/lib/binding_of_callers/version.rb +1 -1
- metadata +11 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5cabef00090223f45e2914553387ecb3e2209d989e5600290cc6143dcb12782f
|
4
|
+
data.tar.gz: 5501a68962a4349b0fa918eae099207d5ceb40369dc91de67aaba1f5d31f0df0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e378a3e420892fe16a45baafb6360dafe4a6c89b08d4858115b8c5aa24886fb25193e0184f52acaf02cc42cb7594127a2ba62b85966fc23c6ed5d5eb21766789
|
7
|
+
data.tar.gz: b4a28b101878884b5741154c223004f5a6cddb85c13c98941aeb895fd804187a68a57846075ed0684531e24f5bb50e8ba708c1af3972e8d68d51d2c21617c0e9
|
data/Gemfile
CHANGED
data/binding_of_callers.gemspec
CHANGED
@@ -20,10 +20,10 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
|
-
spec.add_development_dependency "bundler", "~>
|
23
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
24
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
25
25
|
spec.add_development_dependency "minitest", "~> 5.0"
|
26
26
|
|
27
|
-
spec.add_dependency "binding_of_caller", "~> 0
|
28
|
-
spec.add_dependency "pry", "
|
27
|
+
spec.add_dependency "binding_of_caller", "~> 1.0"
|
28
|
+
spec.add_dependency "pry", ">= 0.10.0"
|
29
29
|
end
|
@@ -1,12 +1,17 @@
|
|
1
1
|
module BindingOfCallers
|
2
2
|
module Reveal
|
3
3
|
|
4
|
+
Klass = Kernel.instance_method(:class)
|
5
|
+
InstanceVariables = Kernel.instance_method(:instance_variables)
|
6
|
+
InstanceVariableGet = Kernel.instance_method(:instance_variable_get)
|
7
|
+
InstanceVariableSet = Kernel.instance_method(:instance_variable_set)
|
8
|
+
|
4
9
|
def _binding
|
5
10
|
instance_variable_defined?(:@_binding) ? @_binding : self
|
6
11
|
end
|
7
12
|
|
8
13
|
def inspect
|
9
|
-
"#<#{self.class}:#{object_id} #{
|
14
|
+
"#<#{self.class}:#{object_id} #{file}:#{line} #{klass}#{call_symbol}#{frame_env}>"
|
10
15
|
end
|
11
16
|
|
12
17
|
def iv *args
|
@@ -32,13 +37,15 @@ module BindingOfCallers
|
|
32
37
|
end
|
33
38
|
|
34
39
|
def klass
|
35
|
-
@klass
|
40
|
+
return @klass if instance_variable_defined? :@klass
|
41
|
+
determine_klass
|
42
|
+
@klass
|
36
43
|
end
|
37
44
|
|
38
45
|
def singleton_method?
|
39
46
|
return @sm if instance_variable_defined? :@sm
|
40
|
-
|
41
|
-
@sm
|
47
|
+
determine_klass
|
48
|
+
@sm
|
42
49
|
end
|
43
50
|
|
44
51
|
def call_symbol
|
@@ -63,28 +70,61 @@ module BindingOfCallers
|
|
63
70
|
|
64
71
|
private
|
65
72
|
|
73
|
+
def determine_klass
|
74
|
+
itself = binding_self
|
75
|
+
@from_object = (Object === itself)
|
76
|
+
binding_class = (@from_object ? itself.class : Klass.bind(itself).call)
|
77
|
+
class_name = binding_class.name
|
78
|
+
if class_name == 'Module' || class_name == 'Class'
|
79
|
+
@sm = true
|
80
|
+
@klass = itself
|
81
|
+
else
|
82
|
+
@sm = false
|
83
|
+
@klass = binding_class
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
66
87
|
def all_iv
|
67
|
-
|
68
|
-
|
69
|
-
|
88
|
+
determine_klass unless instance_variable_defined? :@from_object
|
89
|
+
if @from_object
|
90
|
+
_binding.eval <<-EOS
|
91
|
+
instance_variables.each_with_object({}) do |iv_name, vars|
|
92
|
+
vars[iv_name] = instance_variable_get(iv_name)
|
93
|
+
end
|
94
|
+
EOS
|
95
|
+
else
|
96
|
+
itself = binding_self
|
97
|
+
_instance_variable_get = InstanceVariableGet.bind(itself)
|
98
|
+
InstanceVariables.bind(itself).call.each_with_object({}) do |iv_name, vars|
|
99
|
+
vars[iv_name] = _instance_variable_get.call iv_name
|
70
100
|
end
|
71
|
-
|
101
|
+
end
|
72
102
|
end
|
73
103
|
|
74
104
|
def the_iv name
|
75
|
-
|
105
|
+
determine_klass unless instance_variable_defined? :@from_object
|
106
|
+
if @from_object
|
107
|
+
binding_self.instance_variable_get name
|
108
|
+
else
|
109
|
+
InstanceVariableGet.bind(binding_self).call name
|
110
|
+
end
|
76
111
|
end
|
77
112
|
|
78
113
|
def set_iv name, value
|
79
|
-
|
114
|
+
determine_klass unless instance_variable_defined? :@from_object
|
115
|
+
if @from_object
|
116
|
+
binding_self.instance_variable_set name, value
|
117
|
+
else
|
118
|
+
InstanceVariableSet.bind(binding_self).call name, value
|
119
|
+
end
|
80
120
|
end
|
81
121
|
|
82
122
|
def binding_self
|
83
|
-
_binding.eval "self"
|
123
|
+
_binding.eval "instance_eval('self')"
|
84
124
|
end
|
85
125
|
|
86
126
|
def all_lv
|
87
|
-
_binding.local_variables.each_with_object({}) do |lv_name, vars|
|
127
|
+
_binding.send(:local_variables).each_with_object({}) do |lv_name, vars|
|
88
128
|
vars[lv_name] = the_lv lv_name
|
89
129
|
end
|
90
130
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: binding_of_callers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ken
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,28 +58,28 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0
|
61
|
+
version: '1.0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0
|
68
|
+
version: '1.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: pry
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.10.
|
75
|
+
version: 0.10.0
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.10.
|
82
|
+
version: 0.10.0
|
83
83
|
description:
|
84
84
|
email:
|
85
85
|
- block24block@gmail.com
|
@@ -121,8 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
121
|
- !ruby/object:Gem::Version
|
122
122
|
version: '0'
|
123
123
|
requirements: []
|
124
|
-
|
125
|
-
rubygems_version: 2.6.8
|
124
|
+
rubygems_version: 3.2.3
|
126
125
|
signing_key:
|
127
126
|
specification_version: 4
|
128
127
|
summary: a wrapper of binding_of_caller, for easy use
|