在irb中,我可以按照我的期望进行跟进:
irb(main):001:0> " end ".include? " end " => true
irb(main):002:0> " end ".include? "end" => true
irb(main):003:0> " vendor ".include? "end" => true
irb(main):004:0> " vendor ".include? " end " => false
如果我将以下代码的“end”嵌入名为" line"的变量中,
if line.include? "end"
puts "true when 'end'"
else
puts "false when 'end'"
end
if line.include? " end "
puts "true when ' end '"
else
puts "false when ' end '"
end
我得到以下结果,正如我在IRb中所期望的那样:
Line: end
true when 'end'
false when ' end '