Skip to content

Instantly share code, notes, and snippets.

@metaskills
Created January 10, 2010 13:08
Show Gist options
  • Save metaskills/273507 to your computer and use it in GitHub Desktop.
Save metaskills/273507 to your computer and use it in GitHub Desktop.
class User
def self.space
'Top'
end
end
module MyNamespace
class User
def self.space
'Mine'
end
end
User.space # => "Mine"
end
MyNamespace::User.new # => #<MyNamespace::User:0x10016b970>
User.new # => #<User:0x10016b308>
class MyNamespace::Foo
def self.uspace
User.space
end
def bar
'batz'
end
def uspace
User.space
end
end
MyNamespace::Foo.new.bar # => "batz"
MyNamespace::Foo.uspace # => "Top"
MyNamespace::Foo.new.uspace # => "Top"
module MyNamespace
class Bar
def self.uspace
User.space
end
def bar
'batz'
end
def uspace
User.space
end
def top_uspace
::User.space
end
end
end
MyNamespace::Bar.uspace # => "Mine"
MyNamespace::Bar.new.uspace # => "Mine"
MyNamespace::Bar.new.top_uspace # => "Top"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment