I'm trying to create a module that will be included in many different classes. It needs to record the caller's path to the class file so I can reference the path in later code. This code tries to add a method to the calling class, but fails because it just returns the current value of @@x.
# /home/eric/FindMe.rb class FindMe include GladeGUI end # /home/eric/GladeGUI.rb module GladeGUI def self.included(obj) @@x, = caller[0].partition(":") # this works @@x = "/home/eric/FindMe.rb" obj.class_eval do def my_class_file_path return ????? # I want to return "/home/eric/FindMe.rb" end end end end The GladeGUI module will be "included" in many different classes, so I can't just add code to the calling class. I need a way to make @@x compile into a constant value, so the method stored in the class looks like this:
def my_class_file_path return "/home/eric/FindMe.rb" end How do I convert a variable to a constant in code?
Thanks.