在 Sinatra 应用程序中,我有一个代码
gef '/123' do
@var1 = # some calculations
@var2 = # some calculations
#..... many of them
haml(:"view123")
end
并且所有实例变量都在view123
. 我想知道,使用哈希而不是像这样的许多变量会有什么好处:
gef '/123' do
hash_var = {}
hash_var[:var1] = # some calculations
hash_var[:var2] = # some calculations
#..... many of them
haml(:"view123")
end