Is it right to use @variable in class scope in Ruby? -


I am using the Ruby project in the Ruby class as the frequency variable in the scope of the class.

In the I class method, think square variables @@ var should be used, and in an example method, the frequency variable @ wise should be used.

I want to know that the use of @var in the square is being done correctly?

At present, I know the difference in using variable squares in the variable and class variables in the example that the example variable can not show the expression of the inherited code by the sub-class.

  class Foo @bar = 8 @@bar2 = 10 def self.echo_bar p @bar end def self.echo_bar2 p @@ bar2 end end class Foo2 & lt; Foo end Foo.echo_bar Foo.echo_bar Foo.echo_bar2 Foo2.echo_bar Foo2.echo_bar2 # Result: # 8 # 10 # zero # 10  

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -