summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorFlorian Frank <flori@ping.de>2012-09-20 10:03:17 +0200
committerFlorian Frank <flori@ping.de>2012-12-31 01:34:52 +0100
commit29d4a4f19ff2e64a606e23d18cc8a02ecacd4e4a (patch)
tree34032a9608db3a2f008a56e26683d72e6db1530f /java
parentb24ea03d2dbdb20e676eb40d03042bea2dbd80be (diff)
downloadjson-29d4a4f19ff2e64a606e23d18cc8a02ecacd4e4a.tar.gz
Increase hash likeness of State objects
Diffstat (limited to 'java')
-rw-r--r--java/src/json/ext/GeneratorState.java20
1 files changed, 18 insertions, 2 deletions
diff --git a/java/src/json/ext/GeneratorState.java b/java/src/json/ext/GeneratorState.java
index 58904ee..658d6d0 100644
--- a/java/src/json/ext/GeneratorState.java
+++ b/java/src/json/ext/GeneratorState.java
@@ -262,6 +262,19 @@ public class GeneratorState extends RubyObject {
String name = vName.asJavaString();
if (getMetaClass().isMethodBound(name, true)) {
return send(context, vName, Block.NULL_BLOCK);
+ } else {
+ return getInstanceVariables().getInstanceVariable("@" + name);
+ }
+ }
+
+ @JRubyMethod(name="[]=", required=2)
+ public IRubyObject op_aset(ThreadContext context, IRubyObject vName, IRubyObject value) {
+ String name = vName.asJavaString();
+ String nameWriter = name + "=";
+ if (getMetaClass().isMethodBound(nameWriter, true)) {
+ return send(context, context.getRuntime().newString(nameWriter), value, Block.NULL_BLOCK);
+ } else {
+ getInstanceVariables().setInstanceVariable("@" + name, value);
}
return context.getRuntime().getNil();
}
@@ -480,9 +493,9 @@ public class GeneratorState extends RubyObject {
*
* <p>Returns the configuration instance variables as a hash, that can be
* passed to the configure method.
- * @return
+ * @return the hash
*/
- @JRubyMethod
+ @JRubyMethod(alias = "to_hash")
public RubyHash to_h(ThreadContext context) {
Ruby runtime = context.getRuntime();
RubyHash result = RubyHash.newHash(runtime);
@@ -498,6 +511,9 @@ public class GeneratorState extends RubyObject {
result.op_aset(context, runtime.newSymbol("max_nesting"), max_nesting_get(context));
result.op_aset(context, runtime.newSymbol("depth"), depth_get(context));
result.op_aset(context, runtime.newSymbol("buffer_initial_length"), buffer_initial_length_get(context));
+ for (String name: getInstanceVariableNameList()) {
+ result.op_aset(context, runtime.newSymbol(name.substring(1)), getInstanceVariables().getInstanceVariable(name));
+ }
return result;
}