Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #6439
| From | Robert Klemme <shortcutter@googlemail.com> |
|---|---|
| Newsgroups | comp.lang.ruby |
| Subject | Re: difference between class and object methods |
| Date | 2012-01-31 21:21 +0100 |
| Message-ID | <9or0qdFjmoU1@mid.individual.net> (permalink) |
| References | <c4ed84a5-78ee-442f-80f5-9996b5ffceb7@o12g2000vbd.googlegroups.com> |
On 31.01.2012 13:29, Sagy Drucker wrote:
> 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?
>
> also,
> class variables in ruby are equivalent to static variables in java?
Yep, that's mostly correct. But you should rather not bother to use
class variables (those prefixed with @@) but instead should only use
instance variables of a class, e.g.
class X
def self.a_class_method
@@do_not_use_class_variables = 1
@but_use_class_instance_variables = 2
end
end
Reason is that class variables have weird scoping rules which can
produce strange effects.
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
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