From: Quintus Date: 2010-12-11T22:57:54+09:00 Subject: Re: different between the "::" and "." -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Am 11.12.2010 14:25, schrieb zuerrong: > Hello, > > class Myclass > def Myclass.hi > "hi" > end > def Myclass::hello > "hello" > end > end > > what's the difference between Myclass.hi and Myclass::hello here? > > Thanks. > > In your example they're just the same. But have a look at this: - -------------------------------------- module Foo class Bar end end x = Foo::Bar.new #=> a new instance of Foo::Bar x = Foo.Bar.new #=> error - -------------------------------------- The :: operator is normally used to resolve namespaces--in your example you used it for a class method which is perfectly fine although I think this style is old-ish and not used widely anymore. I personally use the point operator for calling methods on any objects. Classes are just normal objects in Ruby, so why use a special syntax there? Vale, Marvin -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJNA3U1AAoJEGrS0YjAWTKVka0H/0xbCOqH5Gbugleh8b9BpGNX CE6vGbHHuwXaf0rdZTJTL95660hVN1ucFbL2gMH8WKl3A1VqaQQlLdY6EG3sBYEc 7aBlGT54XP9t2B/zRMyHqxgVegbs6HwYyotGYx24FjMtgj/JtXUu0Vq1P2Lf1Jz1 thU0aics3pAbN68xcJdoToe1WCw1KHdvbC4ywZq8fhP3uLyWRqA92l2q28MCz59O P3SkrDoD3yEZBvruCoui7L+SPkqDscdZAt8LrpWFxnZZHxMiMeKL34GdKRdZMYUQ fh4JDuvOeSTRVZKqpgttdxbcwq3e1G1EYVdogIwECSONj2Bh/FiIUYPxPCysjXA= =tKRW -----END PGP SIGNATURE-----