If you are looking at a .phtml file, the first thing to do is to understand that each .phtml file works in the context of some instance of some Block class. So first find out which block class you are in by looking at comments or by typing / echo / var_dumping / etc the value returned by get_class($this) .
Then you can grep the app / code directory to declare a block class, i.e. grep -irn 'class Mage_Catalog_Block_Product_List_Toolbar' app/code/core
Please note that if you use * nix, if you use an IDE, you can simply tell your IDE to teleport you to the class file / declaration, standing on PHP doc comments, such as those found in the main .phtml files, i.e. @see Mage_Catalog_Block_Product_List_Toolbar , and by clicking any shortcut triggers that work on your IDE.
BTW, note on getter methods:
Almost all Magento classes inherit from the Varien_Object class, which implements __ call () - which, if you recall, is triggered when invoking inaccessible methods on the object - so when you call, say, $this->getBananas() on the object, Magento will not generate a fatal error, but instead checks if the internal $data array of the object contains the "bananas" key and returns its value or NULL if it does not exist.
The consequence of this is that sometimes you will see a call like $this->getSomething() , and then you will look for code looking for function getSomething() , but you will not find it because it is not declared anywhere, it is just a template using behavior of the magic getter Varien_Object .
However, the grepping source of Magento super helpful. In addition, if you use the getter function and you cannot find its declaration, then you know that the code simply accesses the data attribute, which is also useful information.