Perl6 Object Oriented Cookbook (v0.2.1)  
Section 2: Attributes and Methods  
 
Recipe 2.17: Changing the Method Signature Based on Caller
Last Updated: Sep 8, 2003
Status: Draft
      Previous Page   Next Page

How important is this problem to you?
  (Login to Vote)
3.50 Rating, 2 Votes  

How acceptable is the proposed solution?
  (Login to Vote)
0.00 Rating, 0 Votes  

Problem:  

You want to create a method that returns different things based on the caller. For example, you may want to return a read-only hash to some callers, and a read-write hash to others.

Solution:  

You can't. Well, you can, but what you probably meant to do was use multimethods.

Discussion:

If you insist, the caller of a method can be determined by introspecting the context in which the method is called.

Issue: Maybe a good example Problem, but what's the best Solution?


Log In to Comment


Login / Edit User Info -- Copyright © 2002 Cognitivity -- Previous Page   Next Page