J
Jos Backus
Any idea how I can access a class constant from within a module when that
module is include'd in the class? I.o.w. how do I make this work?
lizzy:~% cat m
module Debug
def debug(level, msg)
puts msg unless level > DEBUG # XXX DEBUG is wrong!
end
end
class C1
include Debug
DEBUG = 1
def foo
debug(1, "this is foo")
end
end
class C2
include Debug
DEBUG = 2
def bar
debug(1, "this is bar")
end
end
C1.new.foo
C2.new.bar
lizzy:~% ruby m
m:3:in `debug': uninitialized constant Debug:EBUG (NameError)
from m:11:in `foo'
from m:23
lizzy:~%
--
Jos Backus _/ _/_/_/ Sunnyvale, CA
_/ _/ _/
_/ _/_/_/
_/ _/ _/ _/
jos at catnook.com _/_/ _/_/_/ require 'std/disclaimer'
module is include'd in the class? I.o.w. how do I make this work?
lizzy:~% cat m
module Debug
def debug(level, msg)
puts msg unless level > DEBUG # XXX DEBUG is wrong!
end
end
class C1
include Debug
DEBUG = 1
def foo
debug(1, "this is foo")
end
end
class C2
include Debug
DEBUG = 2
def bar
debug(1, "this is bar")
end
end
C1.new.foo
C2.new.bar
lizzy:~% ruby m
m:3:in `debug': uninitialized constant Debug:EBUG (NameError)
from m:11:in `foo'
from m:23
lizzy:~%
--
Jos Backus _/ _/_/_/ Sunnyvale, CA
_/ _/ _/
_/ _/_/_/
_/ _/ _/ _/
jos at catnook.com _/_/ _/_/_/ require 'std/disclaimer'