If variable == 'value' vs if variable?('value')


#1

I see that in chef there are two ways to write if condition in a recipe. They both yield the same result. I want to understand what is the difference between the 2 below if condition. Should one of the if be favored over the other one in recipe or attributes or templates – please explain

Case 1 :-

if node['platform'] == 'centos'
  Chef::Log.info("In if Condition Platform - #{node['platform']}")
elsif node['platform'] == 'ubuntu'
   Chef::Log.info("In elsif condition - Platform -#{node['platform']}")
else
  Chef::Log.info("In else condition - Platform - #{node['platform']}")
end

Case 2 :-

if platform?('centos')
  Chef::Log.info("In if Condition Platform - #{node['platform']}")
elsif platform?('ubuntu')
   Chef::Log.info("In elsif condition - Platform -#{node['platform']}")
else
  Chef::Log.info("In else condition - Platform - #{node['platform']}")
end

Regards,
Vinod Kumar


#2

No difference, entirely up to personal style and aesthetic.