Created
August 12, 2010 00:25
-
-
Save HotFusionMan/520076 to your computer and use it in GitHub Desktop.
initialize_is_not_a_class_method.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In Ruby, initialize is not a class method; it can't access | |
# class instance variables. | |
class C | |
@a = 1 | |
def self.a | |
@a | |
end | |
def initialize | |
@b = self.class.a | |
end | |
attr_reader :b | |
end | |
puts 'value below should be "1":' | |
puts C.new.b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment