subclass - How do you clone the attributes of a superclass's object in Ruby? -


let's have subclass sub class super, , instance of super called super. how create new instance of sub automatically clone of super's properties (and include additional sub properties)? alternatively, can create new instance of super , change class sub?

more detail:

class value < string

attr_accessor ...fields...  def initialize(name, ...fields...)     ...sets fields...     super(name) end  def ...methods... end 

end

class extracted_value

attr_accessor ...more fields...  def initialize(???)     ??? end 

end

i have bunch of different instances of value, , each of them there times when might make extraction utterance, means making new extracted_value contains information how extraction happened, value needs cloned.

my other option try make sort of wrapper class instead of subclass?

class  attr_accessor :a1, :a2   def initialize param1, param2      @a1 = param1    @a2 = param2  end   end  class b <    attr_accessor :b1 end 

when instantiate b class, can call both of a1 , a2 (super) class , can call b1 . can combine in initialize method of sub class wich parameters want set etc ...

b = b.new "foo", 3 puts b.a1 # "foo" puts b.a2 # 3 

hope wanted ?


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -