Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #2971
| From | 7stud -- <bbxx789_05ss@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.ruby |
| Subject | instance_eval trickiness |
| Date | 2011-04-15 13:53 -0500 |
| Organization | Service de news de lacave.net |
| Message-ID | <1bebb61ab4b8db7e05ec21c3f0b37a93@ruby-forum.com> (permalink) |
Hi, I think instance_eval() is the trickiest of the eval's to understand. "Metaprogramming Ruby" says there are two concepts that you have to be aware of: 1) which object is self 2) which object is the current class Unlike self, there is no keyword that you can print out that tells you what the current class is. The most obvious indicator of what the current class is in your code is the 'class' keyword: class Dog ... end Between 'class' and 'end' the current class is Dog. At times it is important to know what the current class is because def's attach themselves to the current class. In the case of classes like Dog, inside the Dog class (but outside of any method definitions)it so happens that self and the current class are the same: class Dog #in here the current class is Dog puts self #=> Dog end -- Posted via http://www.ruby-forum.com/.
Back to comp.lang.ruby | Previous | Next | Find similar | Unroll thread
instance_eval trickiness 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-15 13:53 -0500
csiph-web