On Feb 3, 2011, at 2:16 PM, Albert Català <li...@ruby-forum.com> wrote:

Curtis wrote in post #979429:
On Feb 3, 2011, at 2:57 AM, Albert Catal <li...@ruby-forum.com> wrote:


   super("ERROR------------>"+msg)
 end
end

this is in a file.rb in config/initializers/

and raises the error I said




Did you read my other response about class methods?

Yes but I'm still truing to do that, what do you mean? with

class << self
def error(msg)
  super("ERROR------------>"+msg)
 end
end # class methods Object.method_name

and where do I have to put this code?

Thanks for patience




Hey no worries - so

class A
 def self.error(msg)
  #comment - class method 'error'
  end
end

your first post had the right idea - only error is a method that belongs to the Logger instance - not the dynamic instance.

In A I have a method 'error' that belongs to the A instance.

A.new.error

Would result in a NoMethod on the execution of the code.

class A
  def error
  end
end

A.new.error

Will work now.

You can try this in irb.

You original code had a method that would go on a new instance of Logger - what you needed was a method 'error' on the Logger instance ( refered to in object oriented programming as a the Logger Class)

When the error mentioned that the method could not be found - it is because the 'super' version of the method is actually in Logger the class method error .


Logger.info "assuming we are talking about the same logger•"
--
You received this message because you are subscribed to the Google Groups "Ruby on 
Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to