gpt4 book ai didi

ruby - 了解 Ruby 赋值语法

转载 作者:太空宇宙 更新时间:2023-11-03 17:34:39 25 4
gpt4 key购买 nike

我是 Ruby 的新手,我正在尝试理解这种语法,以便我可以转换为 Groovy。 https://gist.github.com/brettporter/1723108

state = :body

conflict = {
:lineno => index + 1
}

conflict[:left_conflict]

状态和冲突对象是否具有 body 和 lineno 以及 left_conflict 字段?如果是这样, left_conflict 字段是如何填充/分配一个值的?在 Groovy 中这样做的等效方法是什么

最佳答案

Assignment :

In Ruby assignment uses the = (equals sign) character. This example assigns the number five to the local variable v:

v = 5

Assignment creates a local variable if the variable was not previously referenced.

state = :body 被称为一个带有Symbol 的局部变量赋值。实例 :body.

Symbol objects represent names and some strings inside the Ruby interpreter. They are generated using the :name and :"string" literals syntax, and by the various to_sym methods

conflict 也是一个局部变量,它持有一个 Hash对象。

conflict[:left_conflict],这里我们使用方法 Hash#[] 访问哈希值及其键 :left_conflict .:left_conflict是hash对象的key,由conflict局部变量保存。

关于ruby - 了解 Ruby 赋值语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20972114/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com