Skip to content

Instantly share code, notes, and snippets.

@HotFusionMan
Created August 12, 2010 00:25
Show Gist options
  • Save HotFusionMan/520076 to your computer and use it in GitHub Desktop.
Save HotFusionMan/520076 to your computer and use it in GitHub Desktop.
initialize_is_not_a_class_method.rb
# 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