Skip to content

Commit 23b23f8

Browse files
amomchilovst0012
authored andcommitted
Inline variable.rb
1 parent 126b6c2 commit 23b23f8

File tree

4 files changed

+51
-59
lines changed

4 files changed

+51
-59
lines changed

lib/debug/server_cdp.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
require 'tmpdir'
99
require 'tempfile'
1010
require 'timeout'
11-
require_relative 'variable'
1211
require_relative 'variable_inspector'
1312

1413
module DEBUGGER__

lib/debug/server_dap.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
require 'irb/completion'
55
require 'tmpdir'
66
require 'fileutils'
7-
require_relative 'variable'
87
require_relative 'variable_inspector'
98

109
module DEBUGGER__

lib/debug/variable.rb

Lines changed: 0 additions & 56 deletions
This file was deleted.

lib/debug/variable_inspector.rb

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# frozen_string_literal: true
22

3-
require_relative 'variable'
43
require_relative 'limited_pp'
54

65
module DEBUGGER__
@@ -83,4 +82,55 @@ def == other
8382
end
8483
end
8584
end
85+
86+
class Variable
87+
attr_reader :name, :value
88+
89+
def initialize(name:, value:, internal: false)
90+
@name = name
91+
@value = value
92+
@is_internal = internal
93+
end
94+
95+
def internal?
96+
@is_internal
97+
end
98+
99+
def self.internal name:, value:
100+
new(name: name, value: value, internal: true)
101+
end
102+
103+
def inspect_value
104+
@inspect_value ||= if VariableInspector::NaiveString === @value
105+
@value.str.dump
106+
else
107+
VariableInspector.value_inspect(@value)
108+
end
109+
end
110+
111+
def value_type_name
112+
klass = M_CLASS.bind_call(@value)
113+
114+
begin
115+
M_NAME.bind_call(klass) || klass.to_s
116+
rescue Exception => e
117+
"<Error: #{e.message} (#{e.backtrace.first}>"
118+
end
119+
end
120+
121+
def ==(other)
122+
other.instance_of?(self.class) &&
123+
@name == other.name &&
124+
@value == other.value &&
125+
@is_internal == other.internal?
126+
end
127+
128+
def inspect
129+
"#<Variable name=#{@name.inspect} value=#{inspect_value}#{@is_internal ? " internal" : ""}>"
130+
end
131+
132+
# TODO: Replace with Reflection helpers once they are merged
133+
# https://github.com/ruby/debug/pull/1002
134+
M_CLASS = method(:class).unbind
135+
end
86136
end

0 commit comments

Comments
 (0)