aboutsummaryrefslogtreecommitdiffstats
path: root/railties/doc/guides/source/creating_plugins/core_ext.txt
diff options
context:
space:
mode:
authorJeff Dean <jeff@zilkey.com>2008-11-13 01:44:34 -0500
committerJeff Dean <jeff@zilkey.com>2008-11-13 01:44:34 -0500
commit41d0dbcb8661a866ddf4b3534b8b1efd724ecba1 (patch)
treeaa59d83197ea83ded0067241f010baf8e47b3130 /railties/doc/guides/source/creating_plugins/core_ext.txt
parentbc75de8e4f60a774423290872aeb25d09561531b (diff)
downloadrails-41d0dbcb8661a866ddf4b3534b8b1efd724ecba1.tar.gz
rails-41d0dbcb8661a866ddf4b3534b8b1efd724ecba1.tar.bz2
rails-41d0dbcb8661a866ddf4b3534b8b1efd724ecba1.zip
Plugin guide: update acts_as section
Diffstat (limited to 'railties/doc/guides/source/creating_plugins/core_ext.txt')
-rw-r--r--railties/doc/guides/source/creating_plugins/core_ext.txt66
1 files changed, 32 insertions, 34 deletions
diff --git a/railties/doc/guides/source/creating_plugins/core_ext.txt b/railties/doc/guides/source/creating_plugins/core_ext.txt
index 33d3dc8ce7..9bb7691b83 100644
--- a/railties/doc/guides/source/creating_plugins/core_ext.txt
+++ b/railties/doc/guides/source/creating_plugins/core_ext.txt
@@ -5,39 +5,6 @@ This section will explain how to add a method to String that will be available a
* Writing tests for the desired behavior
* Creating and requiring the correct files
-
-=== Working with init.rb ===
-
-When rails loads plugins it looks for the file named init.rb. However, the plugin initializer script 'init.rb' is invoked via `eval` (not `require`) so it has slightly different behavior.
-
-Under certain circumstances if you reopen classes or modules in 'init.rb' itself, you may inadvertently create a new class, rather than reopening an existing class. A better alternative is to reopen the class in a different file, and require that file from `init.rb`.
-
-If you must reopen a class in `init.rb` you can use `module_eval` or `class_eval`:
-
-*vendor/plugins/yaffle/init.rb*
-
-[source, ruby]
----------------------------------------------------
-Hash.class_eval do
- def is_a_special_hash?
- true
- end
-end
----------------------------------------------------
-
-Another way is to explicitly define the top-level module space for all modules and classes, like `::Hash`:
-
-*vendor/plugins/yaffle/init.rb*
-
-[source, ruby]
----------------------------------------------------
-class ::Hash
- def is_a_special_hash?
- true
- end
-end
----------------------------------------------------
-
=== Creating the test ===
In this example you will add a method to String named `to_squawk`. To begin, create a new test file with a few assertions:
@@ -75,7 +42,7 @@ Great - now you are ready to start development.
=== Organize your files ===
-A common pattern in rails plugins is to set up the file structure something like this:
+A common pattern in rails plugins is to set up the file structure like this:
--------------------------------------------------------
|-- init.rb
@@ -124,3 +91,34 @@ $ ./script/console
=> "squawk! Hello World"
--------------------------------------------------------
+=== Working with init.rb ===
+
+When rails loads plugins it looks for the file named init.rb. However, when the plugin is initialized, 'init.rb' is invoked via `eval` (not `require`) so it has slightly different behavior.
+
+Under certain circumstances if you reopen classes or modules in 'init.rb' you may inadvertently create a new class, rather than reopening an existing class. A better alternative is to reopen the class in a different file, and require that file from `init.rb`, as shown above.
+
+If you must reopen a class in `init.rb` you can use `module_eval` or `class_eval` to avoid any issues:
+
+*vendor/plugins/yaffle/init.rb*
+
+[source, ruby]
+---------------------------------------------------
+Hash.class_eval do
+ def is_a_special_hash?
+ true
+ end
+end
+---------------------------------------------------
+
+Another way is to explicitly define the top-level module space for all modules and classes, like `::Hash`:
+
+*vendor/plugins/yaffle/init.rb*
+
+[source, ruby]
+---------------------------------------------------
+class ::Hash
+ def is_a_special_hash?
+ true
+ end
+end
+---------------------------------------------------