如何创建一个末尾有一个数字的对象,该数字在每次使用时都会递增?

发布于 2024-11-16 12:08:46 字数 425 浏览 8 评论 0原文

我正在尝试创建一个变量,每次使用后都可以增加它。 $companyLevel os 是我需要增加的变量。

count = 20
# Variables (20)
while count > 0
 $levelName = ""; 8.times{$levelName  << (65 + rand(25)).chr}
 $companyLevel = "CLev5"
 browser2.button(:id, "addCompanyLevel").click
 sleep 2
 browser2.text_field(:id, $companyLevel).set $levelName
 $companyLevel += 1
 count -= 1
end

如何创建一个末尾有一个数字的变量,该数字在每次使用时都会递增?

谢谢。

I am trying to make a variable that I can increment each time after I use it.
The $companyLevel os the variable that I need to increment.

count = 20
# Variables (20)
while count > 0
 $levelName = ""; 8.times{$levelName  << (65 + rand(25)).chr}
 $companyLevel = "CLev5"
 browser2.button(:id, "addCompanyLevel").click
 sleep 2
 browser2.text_field(:id, $companyLevel).set $levelName
 $companyLevel += 1
 count -= 1
end

How do I create a variable that will have a number at the end that will increment each time it is used?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

謸气贵蔟 2024-11-23 12:08:46

既然你已经有了一个计数,为什么它需要是一个变量呢?为什么不直接进行简单的字符串连接来动态创建您想要的值,

companyLevel = "CLev" + count.to_s

除非您可能需要了解“数组”是什么?

我建议您购买并阅读《Everyday Scripting with Ruby》一书,这是学习 Ruby 语言基础知识并面向测试人员的好方法。

Since you already have a count, why does this need to be a variable? why not just do simple string concatenation to create the value you want on the fly

companyLevel = "CLev" + count.to_s

Unless you need to perhaps read up on what an 'array' is?

I'd suggest you purchase and read the book "Everyday Scripting with Ruby" it's a great way to lean the basics of the ruby language and geared towards testers.

潦草背影 2024-11-23 12:08:46

这是通过创建一个具有递增属性的对象来实现的,而不是通过创建一个递增的变量来实现的。

This is achieved by creating an object with a property that increments not by creating a variable that increments.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文