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

OpenStruct '[]' no method compared with MRI #3113

Closed
ZenGirl opened this issue Jul 7, 2015 · 5 comments
Closed

OpenStruct '[]' no method compared with MRI #3113

ZenGirl opened this issue Jul 7, 2015 · 5 comments

Comments

@ZenGirl
Copy link

ZenGirl commented Jul 7, 2015

MRI 2.2.0:

2.2.0 :001 > require 'ostruct'
 => true
2.2.0 :002 > o = OpenStruct.new(a: 1, b: 2)
 => #<OpenStruct a=1, b=2>
2.2.0 :003 > o.methods
 => [:!, :!=, :!~, :<=>, :==, :===, :=~, :[], :[]=, :__id__, :__send__, :a, :a=, :b, :b=, :class, :clone, :define_singleton_method, :delete_field, :display, :dup, :each_pair, :enum_for, :eql?, :equal?, :extend, :freeze, :frozen?, :hash, :inspect, :instance_eval, :instance_exec, :instance_of?, :instance_variable_defined?, :instance_variable_get, :instance_variable_set, :instance_variables, :is_a?, :itself, :kind_of?, :marshal_dump, :marshal_load, :method, :method_missing, :methods, :modifiable, :new_ostruct_member, :nil?, :object_id, :private_methods, :protected_methods, :public_method, :public_methods, :public_send, :remove_instance_variable, :respond_to?, :send, :singleton_class, :singleton_method, :singleton_methods, :table, :taint, :tainted?, :tap, :to_enum, :to_h, :to_s, :trust, :untaint, :untrust, :untrusted?]
2.2.0 :004 > o.respond_to?("[]")
 => true

JRuby 1.7.19:

jruby-1.7.19 :001 > require 'ostruct'
 => true
jruby-1.7.19 :002 > o = OpenStruct.new(a: 1, b: 2)
 => #<OpenStruct a=1, b=2>
jruby-1.7.19 :003 > o.methods
 => [:!, :!=, :!~, :<=>, :==, :===, :=~, :__id__, :__send__, :a, :a=, :b, :b=, :class, :clone, :com, :define_singleton_method, :delete_field, :display, :dup, :enum_for, :eql?, :equal?, :extend, :freeze, :frozen?, :handle_different_imports, :hash, :include_class, :initialize_clone, :initialize_dup, :inspect, :instance_eval, :instance_exec, :instance_of?, :instance_variable_defined?, :instance_variable_get, :instance_variable_set, :instance_variables, :is_a?, :java, :java_annotation, :java_field, :java_implements, :java_kind_of?, :java_name, :java_package, :java_require, :java_signature, :javafx, :javax, :kind_of?, :marshal_dump, :marshal_load, :method, :methods, :modifiable, :new_ostruct_member, :nil?, :object_id, :org, :private_methods, :protected_methods, :public_method, :public_methods, :public_send, :respond_to?, :respond_to_missing?, :send, :singleton_class, :singleton_methods, :table, :taint, :tainted?, :tap, :to_enum, :to_java, :to_s, :trust, :untaint, :untrust, :untrusted?]
jruby-1.7.19 :004 > o.respond_to?("[]")
 => false
@BanzaiMan
Copy link
Member

#[] appears to be a recent addition to OStruct; it does not exist for 1.9.3, which JRuby 1.7.x aims to follow. For 2.x-compatibility, you'll need to either pass --2.0 (not complete), or use 9k.

@BanzaiMan
Copy link
Member

$ jruby -v --2.0 -S pry
jruby 1.7.19 (2.0.0p598) 2015-01-29 20786bd on Java HotSpot(TM) 64-Bit Server VM 1.8.0_40-b25 +jit [darwin-x86_64]
/Users/asari/.rvm/gems/jruby-1.7.19/gems/pry-0.10.1-java/lib/pry/method.rb:383 warning: instance variable @method not initialized
[1] pry(main)> require 'ostruct'
/Users/asari/.rvm/gems/jruby-1.7.19/gems/pry-0.10.1-java/lib/pry/pager.rb:137 warning: instance variable @system_pager not initialized
=> true
[2] pry(main)> o = OpenStruct.new(a: 1, b: 2)
=> #<OpenStruct a=1, b=2>
[3] pry(main)> o.respond_to? "[]"
=> true

@ZenGirl
Copy link
Author

ZenGirl commented Jul 7, 2015

Hmm. Odd. In any case I found a quick work-around. I'm currently exhausting alternatives to speeding up some 40-odd micro-services by switched from MRI 2.2.0 to JRuby to gain useful threading for the fan-out issue. To my surprise the speedup was negligible. I guess there's nothing "micro" about the service itself. Sigh. Sorry for the interruption. Great work btw.

@nirvdrum
Copy link
Contributor

nirvdrum commented Jul 7, 2015

@ZenGirl Unrelated, but if you have patterns you expected to be faster than they are, please open an issue or hop in IRC (#jruby on Freenode). There is a group of people on IRC that would love to help you out with performance-related matters.

@headius
Copy link
Member

headius commented Jul 7, 2015

Closing as won't fix.

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

No branches or pull requests

4 participants