Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"@@class_var = 'some_value'" inside of ActiveSupport::Concern's 'included' does not work #610

Closed
nbrustein opened this issue Mar 27, 2013 · 1 comment

Comments

@nbrustein
Copy link

The following code will give different results when run in MRI vs. Jruby.

using:

  • jruby 1.7.3 (1.9.3p385) 2013-02-21 dac429b on Java HotSpot(TM) 64-Bit Server VM 1.6.0_37-b06-434-10M3909 [darwin-x86_64]
  • ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin10.8.0]

Code:

module Mod 

  extend ActiveSupport::Concern 

  included do 
    cattr_accessor :var
    @@var = 1
  end

end

class Super
  include Mod
end

class Sub < Super; end

puts Super.var
puts Sub.var


module Mod2 

  extend ActiveSupport::Concern 

  included do 
    cattr_accessor :var
    self.var = 1
  end

end

class Super2
  include Mod2
end

class Sub2 < Super2; end

puts Super2.var
puts Sub2.var

require 'pp'
pp({
  "Super" => Super.var,
  "Sub" => Sub.var,
  "Super2" => Super2.var,
  "Sub2" => Sub2.var
})
@BanzaiMan
Copy link
Member

cattr_accessor is available if you require active_support/core_ext.

$ ruby -v; ruby -r active_support/core_ext gh-610.rb
ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-darwin12.2.1]
1
1
1
1
{"Super"=>1, "Sub"=>1, "Super2"=>1, "Sub2"=>1}
$ jruby -v; jruby -r active_support/core_ext gh-610.rb
jruby 1.7.4.dev (1.9.3p392) 2013-04-08 fd68f31 on Java HotSpot(TM) 64-Bit Server VM 1.7.0_17-b02 [darwin-x86_64]


1
1
{"Super"=>nil, "Sub"=>nil, "Super2"=>1, "Sub2"=>1}

@kares kares closed this as completed Jan 10, 2016
@kares kares added this to the Invalid or Duplicate milestone Jan 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants