- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我有一个模块和一个包含该模块的类。这些不是在同一个文件或同一个文件夹中定义的。我希望模块获取定义该类的目录。
# ./modules/foo.rb
module Foo
def self.included(obj)
obj_dirname = # ??? what goes here?
puts "the class that included Foo was defined in this directory: #{obj_dirname}"
end
end
# ./bar.rb
class Bar
include Foo
end
我希望它的输出是:
the class that included Foo was defined in this directory: ../
这可能吗?如果是,怎么办?
最佳答案
类可以在很多文件中定义,所以你的问题没有真正的答案。另一方面,您可以判断 include Foo
是从哪个文件生成的:
# ./modules/foo.rb
module Foo
def self.included(obj)
path, = caller[0].partition(":")
puts "the module Foo was included from this file: #{path}"
end
end
这将是您正在寻找的路径,除非在其他地方有 MyClass.send :include, Foo
然后定义了 MyClass...
注意:对于 Ruby 1.8.6,需要“向后移植”
或将分区
更改为其他内容。
关于ruby - ruby 模块是否有可能获取定义包含该模块的类的文件的目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3416869/
降本手段一招鲜,增效方法吃遍天; 01 互联网行业里; 降本策略千奇百怪,手段却出奇一致;增效方法五花八门,手段更是花里胡哨; 对于企业来说;
有什么方法可以使用 angularjs 中的部分进行代码分组吗? 原因 --- 我的 Controller 包含太多代码。该 Controller 包含了多个方法和大量功能的代码,降低了代码的可读性。
不幸的是,我的数据库的数据模型必须改变,所以我正在寻找最轻松的方式来迁移我的数据。 此时情况如何: create table cargo{ id serial primary key, per
在 QTextEdit 对象中,假设我想知道字符在鼠标光标下的位置。 我会写... void MyQTextEditObject::mousePressEvent(QMouseEvent* mouse
是否可以在 C++ 中返回一个 return 语句或做一些具有类似功能的事情? 例如,如果代码中有几个函数将指针作为输入,并且每个函数都检查指针是否为 nullptr,这将很方便。如果它是一个 nul
我的 PC 上有一个控制台应用程序,它是 signalR 服务器。 我有一个 html 页面,它是互联网上的 signalR 客户端。但我尝试连接服务器,但我有一个错误的请求 400 错误。如果服务器
我想将应用程序作为后台进程运行。当点击应用程序图标时,它不会显示任何 View ,只会启动后台进程。 最佳答案 对于 iOS 这是不可能的,但是对于 android,react native 有 he
我知道有(昂贵的)框架可以让你在 VS C# 中编写 android 应用程序并将其编译为 android apk。 我也知道,可以在 VS 中编写 Java 应用程序(link)。 是否有可能,甚至
我在做: can :manage, :all if user.role == 'admin' can :approve, Anuncio do |anuncio| anuncio.try(:apr
我是一名优秀的程序员,十分优秀!