logo       

Modifying Struct members: msg#02393

ruby-talk

Subject: Modifying Struct members

Is it possible to modify the members of a Struct class once it's been
created, yet retain all other behavior?

An example:

Thing = Struct.new(:a, :b, :c) do
def some_method
end
end

Is there a way to modify Thing so it behaves as if it were effectively
created like so?

Thing = Struct.new(:a, :b, :c, :d) do
def some_method
end
end

Re-assigning Thing to a new Struct obviously doesn't work because then
the behavior is lost.
Altering Thing.members seemed promising, but that didn't work either.
Adding attr_accessor for :d isn't good because I need Thing.new['d']
to work.

Thoughts?

--
-yossef

<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | Mail Home | sitemap | FAQ | advertise