일부 컨텍스트로: i want to do 나중에 이:
context = Proc.new{}.binding
context.eval 'a = 5'
context.eval 'undef a' # though this doesn't work.
몇 가지 [remove_class_variable] [1], [remove_instance_variable] [2] 와 [remove_const] [3] 지역 변수를 위한 avamer 메서드을 하지만 현재 없습니다.
[1]: https://ruby-doc.org/core/Module.html # method-i-remove_class_variable [2]: https://ruby-doc.org/core/Object.html # method-i-remove_instance_variable [3]: https://ruby-doc.org/core/Module.html # method-i-remove_const
$ irb
irb(main):001:0> a = "a"
=> "a"
irb(main):002:0> defined? a
=> "local-variable"
irb(main):003:0> irb # step into subshell with its own locals
irb#1(main):001:0> defined? a
=> nil
irb#1(main):002:0> a
NameError: undefined local variable or method `a' for main:Object
from /Users/dean/.irbrc:108:in `method_missing'
from (irb#1):2
irb#1(main):003:0> exit
=> #<IRB::Irb: @context=#<IRB::Context:0x1011b48b8>, @signal_status=:IN_EVAL, @scanner=#<RubyLex:0x1011b3df0>>
irb(main):004:0> a # now we're back and a exists again
=> "a"
정신을 될 경우 다른 지역 변수를 범위를 제한할 수 있습니다) 와 같은 내시경이요 com/go/4e6b330a_kr 얽매이지 틀렸다니까 그땅은 이는 특히 뭔가 유용한 경우 로컬 변수, 클래스 정의 및 don& # 39 의 클래스 선언에 주변을 계속 된 것입니다.
내가 생각할 수 있는 유일한 방법으로 이를 '정수' 는 '또는' 어레이입니다 # # 배 등 각 있습니다.
1.times do |a|
a = 5
# code…
end
[5].each do |a|
# code…
end
이 외에 다른 방법을 블록, 심지어 더 올라갈 수 있을 것입니다. 이러한 aren& # 39 로, t, d # 39 로 청소하십시오 I& I&; d love to see if # 39 와 같은 방법을 사용하여 보다 깔끔한 누군가 이 작업을 수행할 수 있습니다.