【发布时间】:2014-10-18 17:13:12
【问题描述】:
我是 ruby 新手,我想尝试将代码 python 转换为 ruby。这将是一个简单的,类似的。
print 'it has' if 'ten' in 'tentacle' else 'None'
【问题讨论】:
标签: ruby
我是 ruby 新手,我想尝试将代码 python 转换为 ruby。这将是一个简单的,类似的。
print 'it has' if 'ten' in 'tentacle' else 'None'
【问题讨论】:
标签: ruby
Ruby String 有方法 include? 所以它会是这样的:
print 'tentacle'.include?('ten') ? 'it has' : 'None'
【讨论】:
如果你使用 rails,你可以使用 'in?':
puts 'ten'.in?('tentacle') ? 'it has' : 'None'
【讨论】: