A
Ara.T.Howard
what i would like to accomplish would be something like this:
class Abstract
class << self
def x
# defined?(self::X) ? self::X : nil
end
end
end
class Concrete < Abstract
X = 42
end
# p Base.x # => nil
# p Derived.x # => 42
does this make sense? in essence i want an abstract class method with the
semantics of "iff a concrete class has defined a certain constant, return it"
the problem is that 'self::X' above tries to reference 'Class::X', if i
replace 'self' with 'Abstract' then i will be referencing the incorrect 'X'...
how does one say 'the constant of the current class' from within a class
method?
-a
--
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
| URL :: http://www.ngdc.noaa.gov/stp/
| TRY :: for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done
===============================================================================
class Abstract
class << self
def x
# defined?(self::X) ? self::X : nil
end
end
end
class Concrete < Abstract
X = 42
end
# p Base.x # => nil
# p Derived.x # => 42
does this make sense? in essence i want an abstract class method with the
semantics of "iff a concrete class has defined a certain constant, return it"
the problem is that 'self::X' above tries to reference 'Class::X', if i
replace 'self' with 'Abstract' then i will be referencing the incorrect 'X'...
how does one say 'the constant of the current class' from within a class
method?
-a
--
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
| URL :: http://www.ngdc.noaa.gov/stp/
| TRY :: for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done
===============================================================================