Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #6443
| From | Danny Woods <dannywoodz@yahoo.co.uk> |
|---|---|
| Newsgroups | comp.lang.ruby |
| Subject | Re: difference between class and object methods |
| References | <c4ed84a5-78ee-442f-80f5-9996b5ffceb7@o12g2000vbd.googlegroups.com> |
| Date | 2012-02-02 21:47 +0000 |
| Message-ID | <m3pqdwaowx.fsf@mirror.lair> (permalink) |
| Organization | SunSITE.dk - Supporting Open source |
Sagy Drucker <sagysrael@gmail.com> writes: > hello > am i correct when i compare to java, and say: > object methods in ruby are equivalent object methods in java > and class methods in ruby are equivalent STATIC functions in java? Instance methods in Ruby can be considered semantically equivalent to instance methods in Java. Ruby's class methods are quite different. In Ruby, classes are themselves objects that are available at runtime (yes, it's somewhat circular), and so can have their own methods and variables. Classes are instances of the class Class (e.g. String.class == Class; this ties up at the end, where Class.class == Class). Java's static methods and variables are not class methods in the same sense. In Java, you cannot refer to 'super' in a static method, as there is no 'this' (q.v. self, the current object; classes aren't objects in Java. In a Ruby class method, 'self', refers to the class object). Since there is no this/self, static methods in Java cannot be overridden in subclasses (although they can be replaced by a static method with the same signature). Being associated with a real object (the class), Ruby class methods can be thought of as instance methods; they're just methods on the class, not an individual instance of it. Hope that helps. Cheers, Danny
Back to comp.lang.ruby | Previous | Next — Previous in thread | Next in thread | Find similar
difference between class and object methods Sagy Drucker <sagysrael@gmail.com> - 2012-01-31 04:29 -0800
Re: difference between class and object methods Robert Klemme <shortcutter@googlemail.com> - 2012-01-31 21:21 +0100
Re: difference between class and object methods Rodrigo Kochenburger <divoxx@gmail.com> - 2012-02-01 07:41 -0800
Re: difference between class and object methods Danny Woods <dannywoodz@yahoo.co.uk> - 2012-02-02 21:47 +0000
Re: difference between class and object methods Alec Ross <alec@arlross.demon.co.uk> - 2012-02-03 11:51 +0000
csiph-web