Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Problem with Module/Class name resolution

Reply
Thread Tools

Problem with Module/Class name resolution

 
 
Thomas Leitner
Guest
Posts: n/a
 
      02-19-2007
Hi,

consider the following:

module A
X = 1
end

p A::X # => 1

module B
include A
end

p B::X # => 1

module A
module Help
p X # => 1
end
end

module B
module Help
p X # => NameError: uninitialized constant B::Help::X
end
end


Why does referencing X from A, B, and A::Help work but not from
B::Help although A is included in B? Is there a work-around to make
this work?

Bye,
Thomas

 
Reply With Quote
 
 
 
 
SonOfLilit
Guest
Posts: n/a
 
      02-19-2007
To expand the knowledge on this weirdness:

irb(main):001:0> module A
irb(main):002:1> module H
irb(main):003:2> end
irb(main):004:1> end
=> nil
irb(main):005:0> module B
irb(main):006:1> include A
irb(main):007:1> end
=> B
irb(main):008:0> module B
irb(main):009:1> module H
irb(main):010:2> end
irb(main):011:1> end
=> nil
irb(main):012:0> A::H.object_id == B::H.object_id
=> false
irb(main):014:0> B::H
=> B::H # it exists

 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
module name versus function name resolution conflict. rocky Python 2 07-07-2009 09:44 AM
LCD TV resolution / DVD resolution ? slonkak DVD Video 0 11-13-2006 02:34 PM
How do you change the Modelsim Cursor Resolution (not simulation resolution) Andrew FPGA VHDL 0 09-26-2005 04:05 AM
Resolution resolution Simon Digital Photography 4 02-27-2004 01:53 PM
ISO Resolution Chart and Printing Resolution Jack Yeazel Digital Photography 0 08-11-2003 11:19 PM



Advertisments