google-cloud-debugger - Class Google::Cloud::Debugger::Breakpoint::Variable (v0.42.2)
Note: Some or all of the information on this page might not apply
to Trusted Cloud. For a list of services that are available in
Trusted Cloud, see Services available for
Trusted Cloud .
Reference documentation and code samples for the google-cloud-debugger class Google::Cloud::Debugger::Breakpoint::Variable.
Variable
Represents a variable or an argument possibly of a compound object
type. Note how the following variables are represented:
A simple Variable:
ruby
x = 5
# Captured variable:
# { name: "x", value: "5", type: "Integer" }
A Compound Variable:
ruby
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:
ruby
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:
ruby
ary = [1, nil]
# Captured variable:
# {
# name: "ary",
# type: "Array",
# members: [
# { name: "[0]", value: "1", type: "Integer" },
# { name: "[1]", value: "nil", type: "NilClass" }
# ]
# }
Methods
.from_rb_var
def self . from_rb_var ( source , name : nil , depth : MAX_DEPTH , var_table : nil , limit : nil ) - > Google :: Cloud :: Debugger :: Breakpoint :: Variable
Convert a Ruby variable into a
Google::Cloud::Debugger::Breakpoint::Variable object. If
a variable table is provided, it will store all the subsequently
created compound variables into the variable table for sharing.
Parameters
source (Any) — Source Ruby variable to convert from
name (String) (defaults to: nil) — Name of the varaible
depth (Integer) (defaults to: MAX_DEPTH) — Number of levels to evaluate in compound
variables. Default to
MAX_DEPTH
var_table (Breakpoint::VariableTable ) (defaults to: nil) — A variable table
to store shared compound variables. Optional.
limit (Integer) (defaults to: nil) — Maximum number of bytes this conversion
should take. This include nested compound member variables'
conversions.
Examples
Simple variable conversion
x = 3 . 0
var = Google :: Cloud :: Debugger :: Breakpoint :: Variable . from_rb_var \
x , name : "x"
var . name #=> "x"
var . value #=> "3.0"
var . type #=> "Float"
Hash conversion
hash = { a : 1 . 0 , b : :two }
var = Google :: Cloud :: Debugger :: Breakpoint :: Variable . from_rb_var \
hash , name : "hash"
var . name #=> "hash"
var . type #=> "Hash"
var . members [ 0 ]. name #=> "a"
var . members [ 0 ]. value #=> "1.0"
var . members [ 0 ]. type #=> "Float"
var . members [ 1 ]. name #=> "b"
var . members [ 1 ]. value #=> ":two"
var . members [ 1 ]. type #=> "Symbol"
Custom compound variable conversion
foo = Foo . new ( a : 1 . 0 , b : [] )
foo . inspect #=> "#<Foo:0xXXXXXX @a=1.0, @b=[]>"
var = Google :: Cloud :: Debugger :: Breakpoint :: Variable . from_rb_var \
foo , name : "foo"
var . name #=> "foo"
var . type #=> "Foo"
var . members [ 0 ]. name #=> "@a"
var . members [ 0 ]. value #=> "1.0"
var . members [ 0 ]. type #=> "Float"
var . members [ 1 ]. name #=> "@b"
var . members [ 1 ]. value #=> "[]"
var . members [ 1 ]. type #=> "Array"
Use variable table for shared compound variables
hash = { a : 1 . 0 }
ary = [ hash , hash ]
var_table = Google :: Cloud :: Debugger :: Breakpoint :: VariableTable . new
var = Google :: Cloud :: Debugger :: Breakpoint :: Variable . from_rb_var \
ary , name : "ary" , var_table : var_table
var . name #=> "ary"
var . var_table_index #=> 0
var_table [ 0 ]. type #=> "Array"
var_table [ 0 ]. members [ 0 ]. name #=> "[0]"
var_table [ 0 ]. members [ 0 ]. var_table_index #=> 1
var_table [ 0 ]. members [ 1 ]. name #=> "[1]"
var_table [ 0 ]. members [ 1 ]. var_table_index #=> 1
var_table [ 1 ]. type #=> "Hash"
var_table [ 1 ]. members [ 0 ]. name #=> "a"
var_table [ 1 ]. members [ 0 ]. type #=> "Float"
var_table [ 1 ]. members [ 0 ]. value #=> "1.0"
#payload_size
def payload_size () - > Integer
Calculate the bytesize of all the attributes and that of the
member variables.
Returns
(Integer) — The total payload size of this variable in bytes.
#set_error_state
def set_error_state ( message , refers_to : StatusMessage :: VARIABLE_VALUE )
Set this variable to an error state by setting the status field
#to_grpc
Exports the Variable to a
Google::Cloud::Debugger::V2::Variable object.
#total_size
def total_size () - > Integer
Calculate the total bytesize of all the attributes and that of the
member variables, plus references into other variables in the
variable table.
Returns
(Integer) — The total payload size of this variable in bytes.
Constants
MAX_DEPTH
value: 3 Max depth to convert on compound variables
MAX_MEMBERS
value: 1000 Max number of member variables to evaluate in compound variables
MAX_STRING_LENGTH
value: 500 Max length on variable inspect results. Truncate extra and replace
with ellipsis.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License , and code samples are licensed under the Apache 2.0 License . For details, see the Google Developers Site Policies . Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-28 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["# google-cloud-debugger - Class Google::Cloud::Debugger::Breakpoint::Variable (v0.42.2)\n\nReference documentation and code samples for the google-cloud-debugger class Google::Cloud::Debugger::Breakpoint::Variable.\n\nVariable\n--------\n\nRepresents a variable or an argument possibly of a compound object\ntype. Note how the following variables are represented:\n\nA simple Variable:\n`ruby\nx = 5\n# Captured variable:\n# { name: \"x\", value: \"5\", type: \"Integer\" }\n`\n\nA Compound Variable:\n`ruby\nclass T\nattr_accessor :m1, :m2\n...\nend\nv = T.new(1, \"2\")\n# Captured variable:\n# {\n# name: \"v\",\n# type: \"T\",\n# members: [\n# { name: "@m1", value: \"1\", type: \"Integer\" },\n# { name: "@m2", value: \"2\", type: \"String\" }\n# ]\n# }\n`\n\nA Hash object:\n`ruby\nhash = { a: 1, b: :two }\n# Captured variable:\n# {\n# name: \"hash\",\n# type: \"Hash\",\n# members: [\n# { name: \"a\", value: \"1\", type: \"Integer\" },\n# { name: \"b\", value: \":2\", type: \"Symbol\" }\n# ]\n# }\n`\n\nAn Array object:\n`ruby\nary = [1, nil]\n# Captured variable:\n# {\n# name: \"ary\",\n# type: \"Array\",\n# members: [\n# { name: \"[0]\", value: \"1\", type: \"Integer\" },\n# { name: \"[1]\", value: \"nil\", type: \"NilClass\" }\n# ]\n# }\n` \n\nInherits\n--------\n\n- Object\n\nMethods\n-------\n\n### .from_rb_var\n\n def self.from_rb_var(source, name: nil, depth: MAX_DEPTH, var_table: nil, limit: nil) -\u003e Google::Cloud::Debugger::Breakpoint::Variable\n\nConvert a Ruby variable into a\nGoogle::Cloud::Debugger::Breakpoint::Variable object. If\na variable table is provided, it will store all the subsequently\ncreated compound variables into the variable table for sharing. \n**Parameters**\n\n- **source** (Any) --- Source Ruby variable to convert from\n- **name** (String) *(defaults to: nil)* --- Name of the varaible\n- **depth** (Integer) *(defaults to: MAX_DEPTH)* --- Number of levels to evaluate in compound variables. Default to [MAX_DEPTH](/ruby/docs/reference/google-cloud-debugger/latest/Google-Cloud-Debugger-Breakpoint-Variable#Google__Cloud__Debugger__Breakpoint__Variable__MAX_DEPTH \"Google::Cloud::Debugger::Breakpoint::Variable::MAX_DEPTH (constant)\")\n- **var_table** ([Breakpoint::VariableTable](./Google-Cloud-Debugger-Breakpoint-VariableTable)) *(defaults to: nil)* --- A variable table to store shared compound variables. Optional.\n- **limit** (Integer) *(defaults to: nil)* --- Maximum number of bytes this conversion should take. This include nested compound member variables' conversions. \n**Returns**\n\n- ([Google::Cloud::Debugger::Breakpoint::Variable](./Google-Cloud-Debugger-Breakpoint-Variable)) --- Converted variable.\n**Examples**\n\nSimple variable conversion \n\n```ruby\nx = 3.0\nvar = Google::Cloud::Debugger::Breakpoint::Variable.from_rb_var \\\n x, name: \"x\"\nvar.name #=\u003e \"x\"\nvar.value #=\u003e \"3.0\"\nvar.type #=\u003e \"Float\"\n```\n\nHash conversion \n\n```ruby\nhash = {a: 1.0, b: :two}\nvar = Google::Cloud::Debugger::Breakpoint::Variable.from_rb_var \\\n hash, name: \"hash\"\nvar.name #=\u003e \"hash\"\nvar.type #=\u003e \"Hash\"\nvar.members[0].name #=\u003e \"a\"\nvar.members[0].value #=\u003e \"1.0\"\nvar.members[0].type #=\u003e \"Float\"\nvar.members[1].name #=\u003e \"b\"\nvar.members[1].value #=\u003e \":two\"\nvar.members[1].type #=\u003e \"Symbol\"\n```\n\nCustom compound variable conversion \n\n```ruby\nfoo = Foo.new(a: 1.0, b: [])\nfoo.inspect #=\u003e \"#\u003cFoo:0xXXXXXX @a=1.0, @b=[]\u003e\"\nvar = Google::Cloud::Debugger::Breakpoint::Variable.from_rb_var \\\n foo, name: \"foo\"\nvar.name #=\u003e \"foo\"\nvar.type #=\u003e \"Foo\"\nvar.members[0].name #=\u003e \"@a\"\nvar.members[0].value #=\u003e \"1.0\"\nvar.members[0].type #=\u003e \"Float\"\nvar.members[1].name #=\u003e \"@b\"\nvar.members[1].value #=\u003e \"[]\"\nvar.members[1].type #=\u003e \"Array\"\n```\n\nUse variable table for shared compound variables \n\n```ruby\nhash = {a: 1.0}\nary = [hash, hash]\nvar_table = Google::Cloud::Debugger::Breakpoint::VariableTable.new\nvar = Google::Cloud::Debugger::Breakpoint::Variable.from_rb_var \\\n ary, name: \"ary\", var_table: var_table\nvar.name #=\u003e \"ary\"\nvar.var_table_index #=\u003e 0\nvar_table[0].type #=\u003e \"Array\"\nvar_table[0].members[0].name #=\u003e \"[0]\"\nvar_table[0].members[0].var_table_index #=\u003e 1\nvar_table[0].members[1].name #=\u003e \"[1]\"\nvar_table[0].members[1].var_table_index #=\u003e 1\nvar_table[1].type #=\u003e \"Hash\"\nvar_table[1].members[0].name #=\u003e \"a\"\nvar_table[1].members[0].type #=\u003e \"Float\"\nvar_table[1].members[0].value #=\u003e \"1.0\"\n```\n\n### #payload_size\n\n def payload_size() -\u003e Integer\n\nCalculate the bytesize of all the attributes and that of the\nmember variables. \n**Returns**\n\n- (Integer) --- The total payload size of this variable in bytes.\n\n### #set_error_state\n\n def set_error_state(message, refers_to: StatusMessage::VARIABLE_VALUE)\n\nSet this variable to an error state by setting the status field\n\n### #to_grpc\n\n def to_grpc()\n\nExports the Variable to a\nGoogle::Cloud::Debugger::V2::Variable object.\n\n### #total_size\n\n def total_size() -\u003e Integer\n\nCalculate the total bytesize of all the attributes and that of the\nmember variables, plus references into other variables in the\nvariable table. \n**Returns**\n\n- (Integer) --- The total payload size of this variable in bytes.\n\nConstants\n---------\n\n### MAX_DEPTH\n\n**value:** 3 \nMax depth to convert on compound variables\n\n### MAX_MEMBERS\n\n**value:** 1000 \nMax number of member variables to evaluate in compound variables\n\n### MAX_STRING_LENGTH\n\n**value:** 500 \nMax length on variable inspect results. Truncate extra and replace\nwith ellipsis."]]