Skip to content

Instantly share code, notes, and snippets.

@githubmo
Last active December 10, 2015 12:38
Show Gist options
  • Save githubmo/4435039 to your computer and use it in GitHub Desktop.
Save githubmo/4435039 to your computer and use it in GitHub Desktop.
class C
@v = "Bah bah"
def m
p @v
p @@v # The Class instance variable is not the same as a class variable
end
def self.m
p @v
end
end
# Create c = C.new
# c.m
# NameError: uninitialized class variable @@v in C
# from /Users/user/Development/ruby/wgr/scope.rb:5:in `m'
# from (irb):4
# from /Users/user/.rbenv/versions/1.9.3-p327/bin/irb:12:in `<main>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment