Whats is the idea behind using self.method_name ??? please help
Thanks.
Whats is the idea behind using self.method_name ??? please help
Thanks.
The first hit in google for ruby def self is
which seems to just about cover it.
Colin
> Whats is the idea behind using self.method_name ??? please help
The first hit in google for ruby def self is
http://yehudakatz.com/2009/11/15/metaprogramming-in-ruby-its-all-abou…
which seems to just about cover it.
Or it could be about disambiguating local variable versus method call. Hard to tell without more context.
Fred
Colin Law wrote in post #1086832:
Read Class method and instance method in model .
Hi ,
Self.methods is static methods using the class name itself you can call the methods and is not available to the instance of the class.
Thanks, Senthil Srinivasan
There is no such thing as static methods in Ruby. self.method_name (or sometimes self.class.method_name) are instance methods on the singleton instance of the object (in 1.9 you can access the singleton via singleton_class too). Since everything is an object in Ruby (literally) you have multiple types of instances, in his case he is accessing instance methods on the singleton (or anonymous class or eigen, however you want to label it) vs instance methods on /an/ instance of that object.
class A def self.b print “this is static methods” end end
You can only be able to call the method “b” by using : A.b
that wat I am trying to say.
Hi Jordon,
Thanks for your information and I agree on wat your saying.
Thanks, Senthil Srinivasan