Jasmine Lognnes
Jasmine Lognnes

Reputation: 7097

Compact if with OR statement doesn't trigger

Inspired by this I now do

hostname = %x{hostname}

if ['staging', 'prod', 'jlpc'].include? hostname
  puts "yes"
end

My Linux hostname is jlpc but it doesn't print out yes.

Why doesn't this work?

Upvotes: 1

Views: 59

Answers (2)

sugaryourcoffee
sugaryourcoffee

Reputation: 879

%x{hostname}
# => "hostname\n"

Solution:

puts "yes" if ['staging', 'prod', 'jlpc'].include? hostname.chomp

Upvotes: 5

Ursus
Ursus

Reputation: 30071

I tried on my machine and that line appends a \n at the end of my hostname. So, try

hostname = %x{hostname}.rstrip

Upvotes: 3

Related Questions