Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #3436
| From | "Jeroen v." <jeroeningen@gmail.com> |
|---|---|
| Newsgroups | comp.lang.ruby |
| Subject | Set attribute of superclass dinamically |
| Date | 2011-04-24 09:29 -0500 |
| Organization | Service de news de lacave.net |
| Message-ID | <ebce7d6a4bf3664dc0904383f9352c21@ruby-forum.com> (permalink) |
I have the following code
class foo
price_per_liter = 1
price
module bar
def set_price val
self.price_per_liter = val
end
end
end
In this way I can succesfully set the price per liter of the class. How
can I make it dunamically, so I can also set the attribute 'price'?
I tried instance_variable_set(@variable, val), but that doesn't work.
Probably because the variables of the class 'foo' and the module 'bar'
lives independent of each other.
--
Posted via http://www.ruby-forum.com/.
Back to comp.lang.ruby | Previous | Next — Next in thread | Find similar | Unroll thread
Set attribute of superclass dinamically "Jeroen v." <jeroeningen@gmail.com> - 2011-04-24 09:29 -0500
Re: Set attribute of superclass dynamically Brian Candler <b.candler@pobox.com> - 2011-04-24 11:00 -0500
Re: Set attribute of superclass dynamically "Jeroen v." <jeroeningen@gmail.com> - 2011-04-24 12:13 -0500
Re: Set attribute of superclass dynamically Brian Candler <b.candler@pobox.com> - 2011-04-24 14:50 -0500
Re: Set attribute of superclass dinamically Josh Cheek <josh.cheek@gmail.com> - 2011-04-24 12:29 -0500
csiph-web