English 中文(简体)
我怎样才能获得一份具有约束力的所有变量清单?
原标题:How can I get a list of all variables in a binding?
  • 时间:2010-01-21 11:50:08
  •  标签:
  • ruby
  • binding

是否有一个<代码>Bled了解其储存的变量? 或者,我是否总是必须结合<条码>在当地使用?

最佳回答

您通过如下文使当地变量清单具有约束力:eval(" local_variables”,_ binding)

我不敢肯定,你所说的“我总是必须结合<条码>使用当地可变<>/代码>?

问题回答

这是一个老的问题,因此,对Ruby <的答复是正确的;=2。

但自2.1以来,新的方法似乎已经形成/形成,并列出地方变量:

local_variable_get  / local_variable_set / local_variable_defined?

现在有 local_variables。 如今,确切地说,“@sepp2k”的答案是什么。

文件:

 local_variables → Array

将具有约束力的地方变量的名称作为象征。

def foo
  a = 1
  2.times do |n|
    binding.local_variables #=> [:a, :n]
  end
end

这种方法是以下法典的简短版本:

binding.eval("local_variables")




相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签