Class variables has been fixed to Singleton instance variables at Rails ... #5759

Merged
merged 1 commit into from Apr 7, 2012

Projects

None yet

2 participants

@romanvbabenko
Contributor

...module

At class << self block we should manipulate with singleton class variables, such as @_env(not @@_env) http://goo.gl/1TtX1

@drogus
Member
drogus commented Apr 7, 2012

Instance variables are fine here. module Rails is essentialy the same as creating new module instance, like Rails = Module.new, so setting them on class << self is ok.

I'm not sure if there is any practical difference /cc @josevalim @jeremy

@romanvbabenko
Contributor
module Rails

  class << self
    def application
      @application = 1
      @@application = 2
    end    
  end

end

Rails.application
puts Rails.send :instance_variable_get, :@application
puts Rails.send :class_variable_get, :@@application

=> 1
=> 2

as you can see it's different variables

module Rails
  class << self
    @@application = 1
  end
end

class Foo
  include Rails

  @@application = 2
end

puts Rails.send :class_variable_get, :@@application

=> 2

i can change @@application directly
i think usage instance singleton class variables more safe in this case and there is no sense in usage @_env & @@application together. @application, @_env more intuitive comprehensive in class << self context

@drogus
Member
drogus commented Apr 7, 2012

@romanvbabenko ah, sorry, from your description I thought that you're changing from instance vars into class vars and you're actually doing the oposite. I'm also in favor of using instance vars here, I just misread your comment.

@drogus drogus merged commit 0864d6d into rails:master Apr 7, 2012
@romanvbabenko
Contributor

n/p tnx i will try to make my comments as informative as possible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment