Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save HotFusionMan/519902 to your computer and use it in GitHub Desktop.
Save HotFusionMan/519902 to your computer and use it in GitHub Desktop.
# Instance methods can only access class-level instance variables via accessor methods (which are themselves class-level methods).
# Here's a demonstration of a more complex situation (in which the instance method in question comes from a mix-in module)
# that illustrates the same principle.
module M
def f
puts self.class.a
end
end
class C
include M
@a = 'Ca'
class << self
attr_reader :a
end
end
puts 'value below should be "Ca"'
C.new.f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment