|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
|
|
#1
|
|||
|
|||
|
Class constants from modules
I'd like to make a class constant using a module -- I cannot use < because I am extending unit_test. -- Here's the idea:
irb(main):001:0> module One @@constant="constant" end => "constant" irb(main):002:0> module Two irb(main):003:1> def work irb(main):004:2> puts(@@constant) irb(main):005:2> end irb(main):006:1> end => nil irb(main):007:0> class Constant_work irb(main):008:1> include One irb(main):009:1> include Two irb(main):010:1> end => Constant_work irb(main):011:0> Constant_work.new.work NameError: uninitialized class variable @@constant in Two from (irb):4:in `work' from (irb):11 irb(main):012:0> How can I get this to happen? Dale |
|
#2
|
|||
|
|||
|
How about:
Code:
irb(main):021:0> module One @@con = "Constant" end => "Constant" irb(main):022:0> module Two include One irb(main):023:1> def work irb(main):024:2> puts(@@con) irb(main):025:2> end irb(main):026:1> end => nil irb(main):027:0> class Constant_work irb(main):028:1> include Two irb(main):029:1> end => Constant_work irb(main):030:0> Constant_work.new.work Constant => nil irb(main):031:0>
__________________
-- I'll provide you with reference points; if they dont work, refer to something else. If you process text, this might make your life a little easier. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Ruby Programming > Class constants from modules |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|