After reading through the Pickaxe book I seem to remember that you can hook
on a variable being set. Could that technique be used here to determine
your answer? If so, it might provide a good FAQ entry.
require ‘postgres’
module Apache
class RubyRun
@@pg_conn_handler = nil
def RubyRun.pg_conn
if !@@pg_conn_handler
.....
I believe that
@@pg_conn_handler = nil
is not set in the context of a method so there will be set an object
variable from … which class?
There was a big overhaul in behavior of class variables (in the
1.6 and 1.7 series) a couple of month ago. Generally speaking,
the new class variable scoping rules is modeled around class
constant rules.
···
$mess =
"There is no such as a ``singleton class’’ class variable,
instead a class/module variable of the surrounding genuine
(non singleton) class or module is created or modified.
"
class Outer
class Inner
end
class << Inner
Const = “Makes sense too!!!”
@@class_var = $mess
def const_mess
puts Const
end
end
def var_mess
puts @@class_var
end
end
make use of const of Singleton class
class Sub < Outer::Inner; end
class Outer
make of use of Outer’s class variable
def Sub.var_mess
puts @@class_var
end
end
Outer.new.var_mess
Sub.var_mess
Sub.const_mess
resulting in
There is no such as a ``singleton class’’ class variable,
instead a class/module variable of the surrounding genuine
(non singleton) class or module is created or modified.
There is no such as a ``singleton class’’ class variable,
instead a class/module variable of the surrounding genuine
(non singleton) class or module is created or modified.