Ruby On Rails

Thursday, October 13, 2011

Class level variables in ruby

We should use @@ to create such variables, they are similar to static variables we see in java or cpp.

class MyClass

@@count = 0 # Initialize a class variable

def initialize # called when object is allocated
@@count += 1
@myvar = 10
end
end

Posted by Rekha Kumari at 3:31 PM
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Labels: class, OOP

No comments:

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments (Atom)

Blog Archive

  • ▼  2011 (28)
    • ▼  October (28)
      • Checking for pallindrome in ruby
      • Converting between values and char
      • Ruby from perspective of other programming languages
      • Primary types in Ruby
      • Comparison of operators with c or other languages
      • Things to remember for ruby
      • Methods and attributes
      • Named parameters in ruby
      • Creating Classes
      • self: Referencing to the current receiver
      • $(function(){$('#tweets').tweetable({username: 'bl...
      • Getters and setters in Ruby class
      • Class level variables in ruby
      • initialize in Ruby vs constructor in Java or cpp
      • Defining functions in ruby
      • Modules and Mixins
      • Built-in classes in Ruby
      • Symbol in ruby
      • Making immutable objects
      • Variables as reference to objects
      • Creating an object in ruby
      • Objects in Ruby
      • Ruby Loops
      • Sample Program in Ruby
      • Operators and precedence in Ruby
      • Comment in Ruby
      • Variables in Ruby
      • Ruby Keywords

About Me

Rekha Kumari
View my complete profile
Simple theme. Powered by Blogger.