class Object
def myLoad (pathToFile)
return load(pathToFile) if $DEBUG
require pathToFile
end
end
myLoad ‘/var/www/hidden/first.rb’
It isn’t finding ‘myLoad’, and so is generating a NameError. This works in
normal Ruby, but not mod_ruby. Could someone explain to me why this is, and
how I could just make a simple globally accessible method like this one?
BTW, if I make it a class method of Object, then Object.myLoad works just
fine.
It isn’t finding ‘myLoad’, and so is generating a NameError. This works in
normal Ruby, but not mod_ruby. Could someone explain to me why this is, and
how I could just make a simple globally accessible method like this one?
It might be the wrapping of the mod_ruby code in an anonymous namespace
that is the reason. This could mean that the Object class you are
defining isn’t the Object class you are expecting, i.e. you are making a
new Object class inside a namespace (more specifically, a module).
Search for the “mod_ruby and module space” thread on rubytalk for more
details.
BTW, if I make it a class method of Object, then Object.myLoad works just
fine.
That is rather odd, and seems to go counter to my point above.
Do you use
class Object; def self.myLoad #etc
or the singleton method way
def Object.myLoad #etc
of defining the class method?
···
–
([ Kent Dahl ]/)_ ~[ http://www.stud.ntnu.no/~kentda/ ]/~
))_student/(( _d L b_/ NTNU - graduate engineering - 5. year )
( __õ|õ// ) )Industrial economics and technological management(
_/ö____/ (_engineering.discipline=Computer::Technology)
That is rather odd, and seems to go counter to my point above.
Do you use
class Object; def self.myLoad #etc
or the singleton method way
def Object.myLoad #etc
of defining the class method?
···
----- Original Message -----
BTW, if I make it a class method of Object, then Object.myLoad works just
fine.
class Object
def Object.myLoad
…
end
end
Object.myLoad # Works just fine.
That doesn’t seem counter to your point at all. If this isn’t really the
Object class, but another one of the same name, then when I type
‘Object.myLoad’, it is using the same class. Basically, it seems I have no
access to the real Object class. Maybe this is a good thing, since it would
still be around for other scripts? (I think?)
Consider this:
def myLoad
…
end
myLoad # Works just fine.
However, myLoad isn’t accessible from other methods/scopes. Is there any
way at all that I can set up this function so that all I can just type
‘myLoad’ anywhere I want and have it work?
However, myLoad isn’t accessible from other methods/scopes. Is there any
way at all that I can set up this function so that all I can just type
‘myLoad’ anywhere I want and have it work?
Been a while since I touched mod_ruby, but I seem to recall that require
would always insert it into the toplevel namespace. So I’d try to
refactor the myLoad out into its own file and require it in the scripts
it is used.
···
–
([ Kent Dahl ]/)_ ~[ http://www.stud.ntnu.no/~kentda/ ]/~
))_student/(( _d L b_/ NTNU - graduate engineering - 5. year )
( __õ|õ// ) )Industrial economics and technological management(
_/ö____/ (_engineering.discipline=Computer::Technology)