Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

块,打包创建时的本地变量引用 #12

Open
duangsuse opened this issue May 13, 2018 · 0 comments
Open

块,打包创建时的本地变量引用 #12

duangsuse opened this issue May 13, 2018 · 0 comments
Labels
enhancement New feature or request semantic Lite semantic 我太菜了,被关了起来 垃圾 duangsuse

Comments

@duangsuse
Copy link
Collaborator

duangsuse commented May 13, 2018

rt, Lite 不支持这种代码:

def a
  @fucking_text = 'deep'
  return ->() { "It's fucking #{@fucking_text} " }
end

puts a().call

可是,其实 Ruby 里的块是在创建时打包当前本地变量的,所以你可以让块携带着本地变量的引用跨越词法作用域的大门, Lite 里这不可能。

def fucking_deep
  @fucking_text = 'deep'
  return { "It's fucking $@fucking_text" }
end

puts funcking_deep().call()
@duangsuse duangsuse added enhancement New feature or request semantic Lite semantic 我太菜了,被关了起来 垃圾 duangsuse labels May 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request semantic Lite semantic 我太菜了,被关了起来 垃圾 duangsuse
Projects
None yet
Development

No branches or pull requests

1 participant