How to get all instances variables in ruby class? -



How to get all instances variables in ruby class? -

i have ruby class, , in 1 of methods, calls external function, , pass in instance variables, , go on homecoming value. here code:

class myclass attr_accessor :name1 attr_accessor :name2 ... attr_accessor :namen def inner_func(): all_vars = ???? # how collect instance variables dict/hash? res = out_func(all_vars) do_more_stuff(res) end end

the problem instance variables might vary in subclasses. can't refer them names. so, there way this? or thinking in wrong way?

you can utilize instance_variables collect them in array. initialized instance variables.

class myclass attr_accessor :name1 attr_accessor :name2 ... attr_accessor :namen def inner_func(): all_vars = instance_variables res = out_func(all_vars) do_more_stuff(res) end end

ruby class variables instance

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -