Ruby Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesRuby Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old June 7th, 2007, 10:27 AM
samp8949 samp8949 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2007
Posts: 1 samp8949 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 3 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old June 19th, 2007, 11:03 PM
L7Sqr L7Sqr is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2004
Location: Constant Limbo
Posts: 585 L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 11 h 31 m 18 sec
Reputation Power: 67
Send a message via AIM to L7Sqr
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesRuby Programming > Class constants from modules


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway