Skip to content

Instantly share code, notes, and snippets.

@sshao
Created May 20, 2015 17:02
Show Gist options
  • Save sshao/e8c975ae4a45b2fdf512 to your computer and use it in GitHub Desktop.
Save sshao/e8c975ae4a45b2fdf512 to your computer and use it in GitHub Desktop.
constant scoping
class Ancestor; end
class Ancestor::DescOne
def self.desc_one_defined?
!!defined?(DescOne)
end
end
# Spork defines Spork::TestFramework::RSpec as:
# Spork::TestFramework::RSpec < Spork::TestFramework
class Ancestor::DescTwo < Ancestor
def self.desc_two_defined?
!!defined?(DescTwo)
end
end
puts "DescOne defined?: #{Ancestor::DescOne.desc_one_defined?}" # returns false
puts "DescTwo defined?: #{Ancestor::DescTwo.desc_two_defined?}" # returns true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment