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

temp_extend breaks the Class #13

Open
ghazel opened this issue May 11, 2011 · 1 comment
Open

temp_extend breaks the Class #13

ghazel opened this issue May 11, 2011 · 1 comment

Comments

@ghazel
Copy link

ghazel commented May 11, 2011

ruby 1.8.7 p249

This was the Rails bug I mentioned on IRC, but it turns out it's fully reproducible without Rails at all. The instance and class methods mimic a piece of class_inheritable_accessor and still demonstrate the problem.

require 'remix'

class Foo
  def self.cls_bar
    1
  end

  def inst_bar
    self.class.cls_bar
  end
end

module Nothing
end

f = Foo.new
p f.inst_bar
f.temp_extend(Nothing) do
  p f.inst_bar
end
p f.inst_bar

results in:

1
1
wtf.rb:9:in `inst_bar': undefined method `cls_bar' for Object:Class (NoMethodError)
        from wtf.rb:21
@banister
Copy link
Owner

banister commented Jun 2, 2011

This is due to Object#class using rb_class_real(). Since i turn the entire inheritance chain into iclasses the original class will no longer be a real class according to this test and so self.class will return Object instead of the actual class.

There are two ways to fix this: (1) prevent remix from turning classes into iclasses unless it really has to. (2) patch the Object#class method so it accepts iclasses inserted by remix as valid classes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants