Dimi
Dimi

Reputation: 193

ruby comparing two identical strings as a condition for if else

I'm attempting to use the comparison of two strings as the condition for my if else statement, but when i compare the string 'true' is printed and the script is terminated. Is there any way to use the string comparison so that the if/else statement will execute?

udhead = string
ddown = string

 if udhead == ddown
    puts 'User directory header pass' && $log.info("User directory header pass")
  else
    puts 'fail' && $log.info("User directory header fail")
  end
end

Upvotes: 1

Views: 273

Answers (1)

konsolebox
konsolebox

Reputation: 75608

You probably meant to use and not &&:

puts 'User directory header pass' and $log.info("User directory header pass")

which evaluates puts and $log.info() separately.

The form you use evaluates like:

puts ('User directory header pass' && $log.info("User directory header pass"))

And is same as

puts (true)

I'm not sure though why you have to join two statements like that when you can just do

puts 'User directory header pass'
$log.info("User directory header pass")

Upvotes: 1

Related Questions