I would like to point out that you were originally using
Book.find_book_by_isbn where it’s only necessary to use
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
inherited from the ActiveRecord::Base class. The AR:B class defines
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
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
string = "Hello "
puts string << “world”
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
yield is basically an output method. It’ll yield whatever’s passed into
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
on it myself.
self is generally the class that you’re currently in. Say you’ve defined
method like this in your app/models/book.rb:
The self here references the class object, Book. Any method you call
this new method definition will be called on a class, rather than an
of that class.
Feel free to add me to MSN and/or GTalk as this email.