I would like to point out that you were originally using Book.find_book_by_isbn where it’s only necessary to use Book.find_by_isbn.
OK, but in model/book.rb, how do I write them to make them different
from instance methods?
What are you trying to do? Redefine the methods for the Book model?
The Book class knows what to do when you call any method on it because it’s inherited from the ActiveRecord::Base class. The AR:B class defines these methods on itself, and any classes that inherit from it automatically inherit these methods as well.
Overriding these methods is not really a good idea unless you know what you’re doing.
I’ve seen some strange syntax with “<” and “yield self” and lines with
just “self” but I find it all confusing, and the pickaxe book seems to
assume you know about this anyway - or at least I don’t find its
examples helpful compared to some of the code I read.
I’m assuming you mean << here. << is the concatenation method. You could do this:
string = "Hello "
puts string << “world”
puts string
and get “Hello world” twice. << modifies anything to the left of it (sometimes referred to as a receiver), and then saves it as that object again, so the next time you do puts string it will automatically be “hello world”.
yield is basically an output method. It’ll yield whatever’s passed into it, in the case you provided it will be self. I’ll need to see this in the proper context before I could explain what it does, but I’ll be a bit shaky on it myself.
self is generally the class that you’re currently in. Say you’ve defined a method like this in your app/models/book.rb:
def self.find_all_hardcovers
end
The self here references the class object, Book. Any method you call within this new method definition will be called on a class, rather than an object of that class.