Skip to content

Commit

Permalink
more idString and make accessor methods work with all encodings.
Browse files Browse the repository at this point in the history
enebo committed Apr 16, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 63fede2 commit 61703bd
Showing 2 changed files with 12 additions and 7 deletions.
11 changes: 4 additions & 7 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
@@ -1871,7 +1871,7 @@ public RubyModule defineModuleUnder(String name) {
}

private void addAccessor(ThreadContext context, RubySymbol identifier, Visibility visibility, boolean readable, boolean writeable) {
String internedIdentifier = identifier.toString();
String internedIdentifier = identifier.idString();

final Ruby runtime = context.runtime;

@@ -1884,17 +1884,14 @@ private void addAccessor(ThreadContext context, RubySymbol identifier, Visibilit
throw runtime.newNameError("invalid attribute name", internedIdentifier);
}

// FIXME: This only works if identifier's encoding is ASCII-compatible
final String variableName = TypeConverter.checkID(runtime, '@' + internedIdentifier).toString();
final String variableName = identifier.asInstanceVariable().idString();
if (readable) {
addMethod(internedIdentifier, new AttrReaderMethod(methodLocation, visibility, variableName));
callMethod(context, "method_added", identifier);
}
if (writeable) {
// FIXME: This only works if identifier's encoding is ASCII-compatible
identifier = TypeConverter.checkID(runtime, internedIdentifier + '=');
internedIdentifier = identifier.toString();
addMethod(internedIdentifier, new AttrWriterMethod(methodLocation, visibility, variableName));
identifier = identifier.asAccessor();
addMethod(identifier.idString(), new AttrWriterMethod(methodLocation, visibility, variableName));
callMethod(context, "method_added", identifier);
}
}
8 changes: 8 additions & 0 deletions core/src/main/java/org/jruby/RubySymbol.java
Original file line number Diff line number Diff line change
@@ -180,6 +180,14 @@ public RubySymbol asAccessor() {
return newIDSymbol(getRuntime(), bytes);
}

public RubySymbol asInstanceVariable() {
ByteList bytes = getBytes().dup();

bytes.prepend((byte) '@');

return newIDSymbol(getRuntime(), bytes);
}

/**
* When we know we need an entry in the symbol table because the provided name will be needed to be
* accessed as a valid identifier later we can call this. If there is not already an entry we will

0 comments on commit 61703bd

Please sign in to comment.