What is a variable defined inside class definition without decorator @ or @@?

In Ruby, such code is legal:

class Aclass
  m = 1

but semantically speaking, what will m be, and how is it supposed to be accessed?


m is just a local variable. It can only be accessed from within the class definition. It could be used to bootstrap the class for instance, but it can't be accessed from anywhere else.

For example:

class Aclass

  puts "m is #{m}"


That code would be run only once, when you require the file containing that class. This is somewhat analogous to Java's static initialisation blocks.

Need Your Help

Foundation insert progress bar into top-bar

html css progress-bar zurb-foundation

I use the framework Foundation 5, i use the top bar and i want to insert into the top-bar a simple progress bar

Wordpress: fatal error no access on control panel/admin panel

php wordpress error-handling ftp wordpress-plugin

During a clean up of my plugins inside of Wordpress i deactivated the: smart archives reloaded plugin.