页: 1 Foo,它为诸如等许多班级的名称空间。 Foo:Bar
,Foo:Baz
等。
是否有办法按<代码>重新命名所有类别名称。 Foo
页: 1 Foo,它为诸如等许多班级的名称空间。 Foo:Bar
,Foo:Baz
等。
是否有办法按<代码>重新命名所有类别名称。 Foo
Foo.constants
页: 1 Foo。 这包括但不限于类别名称。 如果你只想人种名,你可以使用。
Foo.constants.select {|c| Foo.const_get(c).is_a? Class}
如果你想要分类和模块名称,你可以使用<代码>is_a? 页: 1 类别代码>。
如果你不喜欢“
Foo.constants.map(&Foo.method(:const_get)).grep(Class)
In short no. However, you can show all classes that have been loaded. So first you have to load all classfiles in the namespace:
Dir["#{File.dirname(__FILE__)}/lib/foo/*.rb"].each {|file| load file}
然后,你可以采用诸如Jörg W Mittag等方法,列出这些班级。
Foo.constants.map(&Foo.method(:const_get))。grep(Class)
This will only return the loaded constants under the given namespace because ruby uses a lazy load approach. So, if you type
Foo.constants.select {|c| Foo.const_get(c).is_a? Class}
页: 1
[]
但在打字之后:
Foo::Bar
页: 1
[:Bar]
这一替代解决办法将装上all<>m>m>。 <代码>Foo: , 包括“嵌入”类别,例如Foo:Bar:Bar<>/code>。
Dir["#{File.dirname(__FILE__)}/lib/foo/**/*.rb"].each { |file| load file }
ObjectSpace.each_object(Class).select { |c| c.to_s.start_with? "Foo::" }
注:**/*.rb
可追溯生效。
请列入<代码> 缩略语/代码类别本身,请将<条码>电子显示/编码>改为:<条码>;>;>;>;<>;>;>; >; >; ......
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 ...
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 ...
All of the following API do the same thing: open a file and call a block for each line. Is there any preference we should use one than another? File.open("file").each_line {|line| puts line} open("...
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?
Here s the string: 04046955104021109 I need it to be formatted like so: 040469551-0402-1109 What s the shortest/most efficient way to do that with ruby?
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
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 ...
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 ...