简体   繁体   English

如何在Ruby中搜索定义的常量

[英]How to search defined constants in ruby

How can I show all defined constants with the word "AjaxDatatablesRails" in it? 如何显示所有带有"AjaxDatatablesRails"字样的已定义常量?

I tried this: 我尝试了这个:

::AjaxDatatablesRails::Extensions
# >> NameError: uninitialized constant AjaxDatatablesRails::Extensions
Module.constants.grep /AjaxDatatablesRails/

Module.constants returns an array of the names of all constants accessible from the point of call. Module.constants返回从调用点可以访问的所有常量的名称的数组。

Enumerable#grep then loops through this array, and filters out the names matching the given pattern. 然后, Enumerable#grep遍历此数组,并过滤​​出与给定模式匹配的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM