ruby on rails - Accessing class method from an instance method -


say have following code

class monster   def self.yell     'i yelling!'   end    def shout_something     monster.yell   end end 

my yell method class method while shout_something instance method calls yell.

is there inherently wrong doing this? example, bad call class method instance method? ask because feels wrong maybe it's because i'm newbie ruby.

on side note, thought doing self.yell instead of monster.yell make more sense doesn't work.

there's nothing particularly wrong calling class method instance method. depending on intent , how want people subclass monster, might want use this:

def shout_something     self.class.yell end 

so subclasses can provide yell class method.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -