Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #2302
| From | Luk Mus <support@fit4u.su> |
|---|---|
| Newsgroups | comp.lang.ruby |
| Subject | Autoconvert object from one class1 to other class2 in class1 def |
| Date | 2011-04-05 03:02 -0500 |
| Organization | Service de news de lacave.net |
| Message-ID | <5095fcbac456c1c2b31e5c05fbea960d@ruby-forum.com> (permalink) |
Is it possible to convert from one Class1 to another Class2 within the
functions of the Class1?
Example:
class String
def to_i!
self=self.to_i
end
end
c='1' # c='1' - String
c.to_i! # c=1 - Integer
Previous code is wrong, error:
Can't change the value of self
self=self.to_i
--
Posted via http://www.ruby-forum.com/.
Back to comp.lang.ruby | Previous | Next — Next in thread | Find similar | Unroll thread
Autoconvert object from one class1 to other class2 in class1 def Luk Mus <support@fit4u.su> - 2011-04-05 03:02 -0500
Re: Autoconvert object from one class1 to other class2 in class1 def Luk Mus <support@fit4u.su> - 2011-04-05 03:19 -0500
Re: Autoconvert object from one class1 to other class2 in class1 def Brian Candler <b.candler@pobox.com> - 2011-04-05 03:46 -0500
Re: Autoconvert object from one class1 to other class2 in class1 def Luk Mus <support@fit4u.su> - 2011-04-05 04:15 -0500
Re: Autoconvert object from one class1 to other class2 in class1 def Brian Candler <b.candler@pobox.com> - 2011-04-05 07:41 -0500
Re: Autoconvert object from one class1 to other class2 in class1 def Adam Prescott <adam@aprescott.com> - 2011-04-05 07:50 -0500
Re: Autoconvert object from one class1 to other class2 in class1 def Robert Klemme <shortcutter@googlemail.com> - 2011-04-05 07:56 -0500
csiph-web