我有一个承诺,我必须得到内部的价值,但它的def balanced_parens(string, parens_map)
# where we throw opening parens
opening_parens = []
i = 0
while i < string.length
# if current index is opening paren add to array
if parens_map.keys.include? string[i]
opening_parens << string[i]
# if current index is closing paren, remove last item from opening_array
elsif parens_map.values.include? string[i]
popped_paren = opening_parens.pop
# checking that closing parens at current index is a match for last open parens in opening_array
return false if string[i] != parens_map[popped_paren]
end
i += 1
end
# if opening_parens array is empty, all parens have been matched (&& value = true)
opening_parens.empty?
end
和<value>
属性似乎无法通过常规手段访问。我以前从未见过具有<state>
外观的属性,所以我认为这可能是线索。
如何访问这些属性?
编辑:我找到了一种方法,但它不是重复问题的答案将代码粘贴到控制台的代码:
<bracketed>