aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/source
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2009-06-13 00:52:27 +0200
committerXavier Noria <fxn@hashref.com>2009-06-13 01:10:22 +0200
commitfe0cf9213ce227730ece1b92f9828dcc6ad43977 (patch)
tree5d51e528d983008fc1f0e9161d717315e3758dff /railties/guides/source
parente20e0c8c4260e3718a77367f1b3d7546305defaa (diff)
downloadrails-fe0cf9213ce227730ece1b92f9828dcc6ad43977.tar.gz
rails-fe0cf9213ce227730ece1b92f9828dcc6ad43977.tar.bz2
rails-fe0cf9213ce227730ece1b92f9828dcc6ad43977.zip
AS guide: explains acts_like?
Diffstat (limited to 'railties/guides/source')
-rw-r--r--railties/guides/source/active_support_overview.textile17
1 files changed, 17 insertions, 0 deletions
diff --git a/railties/guides/source/active_support_overview.textile b/railties/guides/source/active_support_overview.textile
index ab9390883b..a88432dc3b 100644
--- a/railties/guides/source/active_support_overview.textile
+++ b/railties/guides/source/active_support_overview.textile
@@ -78,6 +78,23 @@ class Proc
end
</ruby>
+h4. +acts_like?(duck)+
+
+The method +acts_like+ provides a way to check whether some class acts like some other class based on a simple convention: a class that provides the same interface as +String+ defines
+
+<ruby>
+def acts_like_string?
+end
+</ruby>
+
+which is only a marker, its body or return value are irrelevant. Then, client code can query for duck-type-safeness this way:
+
+<ruby>
+some_klass.acts_like?(:string)
+</ruby>
+
+Rails has classes that act like +Date+ or +Time+ and follow this contract.
+
h3. Extensions to +Module+
...