假设我在函数中有一个静态变量:
Private Sub SomeFunction()
Static staticVar As String = _myField.Value
End Sub
Run Code Online (Sandbox Code Playgroud)
确切地说,_myField分配给staticVar的值是什么时候?第一次打电话给这个功能?封闭类的实例化?
抱歉这个令人困惑的标题,不知道如何描述这个问题.
在Ruby on Rails控制器中,我正在创建一个名为的列表@commits,其中每个项@commits应包含一个哈希表,其元素是每个提交的各种属性的值.这些属性值存储在Redis数据库中.
下面,我遍历一个属性列表,其中的值应该从Redis中获取,然后为8个不同的提交中的每一个获取这些值.然后我使用提交属性名称作为哈希的键,将redis中的值放入每个提交的不同哈希表中.
# Initialize @commits as a list of eight empty hash tables
@commits = Array.new(8, {})
# Iterate over the attributes that need hashed for each item in @commits
[:username, :comment, :rev, :repo].each do |attrib|
# 8 items in @commits
8.times do |i|
# Get a value from redis and store it in @commits[i]'s hash table
@commits[i][attrib] = $redis.lindex(attrib, i)
# Print the value stored in the hash
# Outputs 7, 6, …Run Code Online (Sandbox Code Playgroud)