Coming soon - Get a detailed view of why an account is flagged as spam!
view details
3
Can nested classes reference themselves?
Post Body

I expected that a nested class can reference itself without having to reference its enclosing modules. This doesn't appear to be the case though:

module Foo; end
 => nil

module Foo::Bar
  class Baz; end;
end
 => nil

class Baz
  def say
    "::Baz"
  end
 end
 => nil

class Foo::Bar::Baz
  def say; "::Foo::Bar::Baz"; end;
  def x; Baz.new.say; end
end
 => nil

# expected "Foo::Bar::Baz"
Foo::Bar::Baz.new.x
 => "::Baz"

Have I misunderstood how constants work?

Author
Account Strength
100%
Account Age
14 years
Verified Email
Yes
Verified Flair
No
Total Karma
162,670
Link Karma
59,124
Comment Karma
102,290
Profile updated: 3 days ago
Posts updated: 8 months ago
jxf

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
13 years ago