Permalink
Browse files

JRUBY-131: Constants should not be instance variables (partial)

  This fix only makes sure no instance will return a constant when they call instance_variables
  Leaving open...

git-svn-id: http://svn.codehaus.org/jruby/trunk/jruby@2360 961051c9-f516-0410-bf72-c9f7e237a7b7
  • Loading branch information...
1 parent a121a4e commit 7c963d58934e0c3fff5d96f4808e44c786fd3a2c @enebo enebo committed Oct 20, 2006
Showing with 13 additions and 1 deletion.
  1. +6 −1 src/org/jruby/RubyObject.java
  2. +7 −0 test/testClass.rb
@@ -947,7 +947,12 @@ public RubyBoolean instance_of(IRubyObject type) {
public RubyArray instance_variables() {
ArrayList names = new ArrayList();
for(Iterator iter = getInstanceVariablesSnapshot().keySet().iterator();iter.hasNext();) {
- names.add(getRuntime().newString((String)iter.next()));
+ String name = (String) iter.next();
+
+ // Do not include constants which also get stored in instance var list in classes.
+ if (!Character.isUpperCase(name.charAt(0))) {
+ names.add(getRuntime().newString(name));
+ }
}
return getRuntime().newArray(names);
}
View
@@ -200,3 +200,10 @@ class SubClass < BaseClass
x = SubClass.new
test_no_exception { x.foo }
test_equal([SubClass, BaseClass], $foo_calls)
+
+class NoConstantInInstanceVariables
+ @@b = 4
+ B = 2
+end
+
+test_equal(["@@b"], NoConstantInInstanceVariables.new.class.instance_variables)

0 comments on commit 7c963d5

Please sign in to comment.