MCPcopy
hub / github.com/d4l3k/go-pry / Set

Method Set

pry/interpreter.go:104–132  ·  view source on GitHub ↗

Set walks the scope and sets a value in a parent scope if it exists, else current.

(name string, val interface{})

Source from the content-addressed store, hash-verified

102
103// Set walks the scope and sets a value in a parent scope if it exists, else current.
104func (scope *Scope) Set(name string, val interface{}) {
105 if val != nil {
106 value := reflect.ValueOf(val)
107 if !value.CanAddr() {
108 nv := reflect.New(value.Type())
109 nv.Elem().Set(value)
110 val = nv.Interface()
111 } else {
112 val = value.Addr().Interface()
113 }
114 }
115
116 exists := false
117 currentScope := scope
118 for !exists && currentScope != nil {
119 currentScope.Lock()
120 _, exists = currentScope.Vals[name]
121 if exists {
122 currentScope.Vals[name] = val
123 }
124 currentScope.Unlock()
125 currentScope = currentScope.Parent
126 }
127 if !exists {
128 scope.Lock()
129 scope.Vals[name] = val
130 scope.Unlock()
131 }
132}
133
134// Keys returns all keys in scope
135func (scope *Scope) Keys() (keys []string) {

Callers 15

NewScopeFunction · 0.95
InterpretMethod · 0.95
TestTypeCastFunction · 0.95
TestBasicIdentFunction · 0.95
TestMapIdentFunction · 0.95
TestMissingMapIdentFunction · 0.95
TestArrIdentFunction · 0.95
TestMissingArrIdentFunction · 0.95
TestSliceFunction · 0.95
TestSelectorFunction · 0.95
TestStructLiteralFunction · 0.95
TestStructLiteralNamedFunction · 0.95

Calls

no outgoing calls

Tested by 15

TestTypeCastFunction · 0.76
TestBasicIdentFunction · 0.76
TestMapIdentFunction · 0.76
TestMissingMapIdentFunction · 0.76
TestArrIdentFunction · 0.76
TestMissingArrIdentFunction · 0.76
TestSliceFunction · 0.76
TestSelectorFunction · 0.76
TestStructLiteralFunction · 0.76
TestStructLiteralNamedFunction · 0.76
TestStructLiteralEmptyFunction · 0.76