Created
August 27, 2016 05:56
-
-
Save raj454raj/eaac869fa59a6b69c3f84920896da755 to your computer and use it in GitHub Desktop.
Class variables in Ruby
This file contains 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
class Temp | |
@@count = 0 | |
def initialize | |
@@count += 1 | |
end | |
def self.count | |
@@count | |
end | |
end | |
puts Temp.count.to_s + " " + Temp.class_eval('@@count').to_s | |
Temp.new | |
puts Temp.count.to_s + " " + Temp.class_eval('@@count').to_s | |
Temp.new | |
puts Temp.count.to_s + " " + Temp.class_eval('@@count').to_s | |
Temp.new | |
puts Temp.count.to_s + " " + Temp.class_eval('@@count').to_s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment