尝试使用该语言我发现select
在全局范围内定义,其优先级高于局部变量。
def example(select)
puts select
end
example 3
# Syntax error in eval:3: unexpected token: end (expecting when, else or end)
所以逐步尝试选择我得到这个:
select 1 end
# Syntax error in eval:3: unexpected token: end (expecting when, else or end)
然后
select when 1 end
# Syntax error in eval:1: invalid select when expression: must be an assignment or call
然后
select when x = 1 end
# Syntax error in eval:1: invalid select when expression: must be an assignment or call
然后
select when x
# Syntax error in eval:1: unexpected token: EOF (expecting ',', ';' or '
我会跳过几步,因为你应该知道我是如何回答我的问题...
select when x;
else y
end
# Error in line 1: undefined local variable or method 'x_select_action'
最后
x_select_action = 4
select when x;
else y
end
# Error in line 3: undefined method 'x_select_action' (If you declared 'x_select_action' in a suffix if, declare it in a regular if for this to work. If the variable was declared in a macro it's not visible outside it)
因此,该语言中的关键字在局部变量优先级之前,我不知道它的用途。但显然,当x_select_action
作为when子句给出时,它会查找x
。这是什么select
以及如何使用它?
在线搜索我看到select
在Enumerable,Hash,Channel和Array上定义了......但乍一看似乎不是这样。
感谢您的帮助!