Skip to content

Instantly share code, notes, and snippets.

@bernerdschaefer
Created February 11, 2010 23:09
Show Gist options
  • Save bernerdschaefer/302090 to your computer and use it in GitHub Desktop.
Save bernerdschaefer/302090 to your computer and use it in GitHub Desktop.
## Sibling constant resolution/scoping
module X
class Y; end
end
class X::Z
def self.y
Y
end
end
X::Z.class_eval "Module.nesting" # [X::Y::Z]
X::Z.const_get(:Y) # uninitialized constant X::Z::Y
X::Z.y # uninitialized constant X::Z::Y
## Parent constant resolution/scoping
module X
class Y; end
end
class X::Y::Z
def self.y
Y
end
end
X::Y::Z.class_eval "Module.nesting" # [X::Y::Z]
X::Y::Z.const_get(:Y) # uninitialized constant X::Y::Z::Y
X::Y::Z.y # uninitialized constant X::Y::Z::Y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment