diff options
author | Florian Frank <flori@ping.de> | 2012-09-20 10:03:17 +0200 |
---|---|---|
committer | Florian Frank <flori@ping.de> | 2012-12-31 01:34:52 +0100 |
commit | 29d4a4f19ff2e64a606e23d18cc8a02ecacd4e4a (patch) | |
tree | 34032a9608db3a2f008a56e26683d72e6db1530f /java/src/json/ext | |
parent | b24ea03d2dbdb20e676eb40d03042bea2dbd80be (diff) | |
download | json-29d4a4f19ff2e64a606e23d18cc8a02ecacd4e4a.tar.gz |
Increase hash likeness of State objects
Diffstat (limited to 'java/src/json/ext')
-rw-r--r-- | java/src/json/ext/GeneratorState.java | 20 |
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; } |