R
rtilley
Is it proper to return something while in a code block like this:
def test_get_os
# Get the OS version.
wmi = WIN32OLE.connect("winmgmts:\\\\.")
wmi.InstancesOf("win32_operatingsystem").each do |o|
os = o.caption
return os
end
end
Or, is it more appropriate to return outside of the block like this:
def test_get_os
# Get the OS version.
os = ''
wmi = WIN32OLE.connect("winmgmts:\\\\.")
wmi.InstancesOf("win32_operatingsystem").each do |o|
os = o.caption
end
return os
end
Maybe I'm being too pedantic, I'm just curious as to which way is better.
Thanks,
Brad
def test_get_os
# Get the OS version.
wmi = WIN32OLE.connect("winmgmts:\\\\.")
wmi.InstancesOf("win32_operatingsystem").each do |o|
os = o.caption
return os
end
end
Or, is it more appropriate to return outside of the block like this:
def test_get_os
# Get the OS version.
os = ''
wmi = WIN32OLE.connect("winmgmts:\\\\.")
wmi.InstancesOf("win32_operatingsystem").each do |o|
os = o.caption
end
return os
end
Maybe I'm being too pedantic, I'm just curious as to which way is better.
Thanks,
Brad