Permalink
Browse files

AS guide: explains acts_like?

  • Loading branch information...
1 parent e20e0c8 commit fe0cf9213ce227730ece1b92f9828dcc6ad43977 @fxn fxn committed Jun 12, 2009
Showing with 17 additions and 0 deletions.
  1. +17 −0 railties/guides/source/active_support_overview.textile
View
17 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+
...

0 comments on commit fe0cf92

Please sign in to comment.