A
Ara.T.Howard
is this an appropriate way to inherit constants?
~/eg/ruby > cat a.rb
#!/usr/bin/env ruby
class A
OPTIONS = 1, 0
def klass; self.class; end
def options
opts = []
k = klass
loop do
opts.push(*k::OPTIONS)
k = k.superclass
break unless defined?(k::OPTIONS)
end
opts
end
end
class B < A
OPTIONS = 3, 2
end
class C < B
OPTIONS = 5, 4
end
p A.new.options
p B.new.options
p C.new.options
~/eg/ruby > ruby a.rb
[1, 0]
[3, 2, 1, 0]
[5, 4, 3, 2, 1, 0]
-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
===============================================================================
~/eg/ruby > cat a.rb
#!/usr/bin/env ruby
class A
OPTIONS = 1, 0
def klass; self.class; end
def options
opts = []
k = klass
loop do
opts.push(*k::OPTIONS)
k = k.superclass
break unless defined?(k::OPTIONS)
end
opts
end
end
class B < A
OPTIONS = 3, 2
end
class C < B
OPTIONS = 5, 4
end
p A.new.options
p B.new.options
p C.new.options
~/eg/ruby > ruby a.rb
[1, 0]
[3, 2, 1, 0]
[5, 4, 3, 2, 1, 0]
-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
===============================================================================