我可以覆盖`.< digit>`来指向数组的索引吗? [英] Can I override `.<digit>` to point at an index for an array?

查看:74
本文介绍了我可以覆盖`.< digit>`来指向数组的索引吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.<digit>表示将数字解释为浮点数而不是整数.

我可以重写.<digit>使其指向数组中的索引,以便以下内容可以工作吗?

c = [1, 2, 3, 4, 5, 6]
c.0 # => 1
c.3 # => 4

解决方案

否.方法名称不能以Ruby中的数字开头. 此处.. >

.<digit> means to interpret the number as a float instead of an integer.

Can I override .<digit> to let it point the index in an array so that the following will work?

c = [1, 2, 3, 4, 5, 6]
c.0 # => 1
c.3 # => 4

解决方案

No. A method name can't begin with a number in Ruby. More about Ruby method names restrictions here.

这篇关于我可以覆盖`.&lt; digit&gt;`来指向数组的索引吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆