Class: Google::Cloud::Debugger::Breakpoint::Variable
- Inherits:
-
Object
- Object
- Google::Cloud::Debugger::Breakpoint::Variable
- Defined in:
- lib/google/cloud/debugger/breakpoint/variable.rb
Overview
Variable
Represents a variable or an argument possibly of a compound object type. Note how the following variables are represented:
A simple Variable:
x = 5
# Captured variable:
# { name: "x", value: "5", type: "Integer" }
A Compound Variable:
class T
attr_accessor :m1, :m2
...
end
v = T.new(1, "2")
# Captured variable:
# {
# name: "v",
# type: "T",
# members: [
# { name: "@m1", value: "1", type: "Integer" },
# { name: "@m2", value: "2", type: "String" }
# ]
# }
A Hash object:
hash = { a: 1, b: :two }
# Captured variable:
# {
# name: "hash",
# type: "Hash",
# members: [
# { name: "a", value: "1", type: "Integer" },
# { name: "b", value: ":2", type: "Symbol" }
# ]
# }
An Array object:
ary = [1, nil]
# Captured variable:
# {
# name: "ary",
# type: "Array",
# members: [
# { name: "[0]", value: "1", type: "Integer" },
# { name: "[1]", value: "nil", type: "NilClass" }
# ]
# }
Constant Summary collapse
- MAX_DEPTH =
Max depth to convert on compound variables
3
- MAX_MEMBERS =
Max number of member variables to evaluate in compound variables
10
- MAX_STRING_LENGTH =
Max length on variable inspect results. Truncate extra and replace with ellipsis.
260
Class Method Summary collapse
-
.from_rb_var(source, name: nil, depth: MAX_DEPTH) ⇒ Google::Cloud::Debugger::Breakpoint::Variable
Convert a Ruby variable into a Google::Cloud::Debugger::Breakpoint::Variable object.
Class Method Details
.from_rb_var(source, name: nil, depth: MAX_DEPTH) ⇒ Google::Cloud::Debugger::Breakpoint::Variable
Convert a Ruby variable into a Google::Cloud::Debugger::Breakpoint::Variable object.
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/google/cloud/debugger/breakpoint/variable.rb', line 177 def self.from_rb_var source, name: nil, depth: MAX_DEPTH return source if source.is_a? Variable # If source is a non-empty Array or Hash, or source has instance # variables, evaluate source as a compound variable. if (((source.is_a?(Hash) || source.is_a?(Array)) && !source.empty?) || !source.instance_variables.empty?) && depth > 0 from_compound_var source, name: name, depth: depth else var = Variable.new var.name = name.to_s if name var.type = source.class.to_s var.value = truncate_value(source.inspect) var end end |