Perl6 Object Oriented Cookbook (v0.2.1)  
Section 2: Attributes and Methods  
 
Recipe 2.6: Creating Methods
Last Updated: Sep 8, 2003
Status: Very Likely
      Previous Page   Next Page

How important is this problem to you?
  (Login to Vote)
5.00 Rating, 4 Votes  

How acceptable is the proposed solution?
  (Login to Vote)
5.00 Rating, 2 Votes  

Problem:  

You want to declare a method of a class.

Solution:  

Use the method keyword:

class MyClass {
    method do_something {
        ...
    }
}

Discussion:

Methods of a class are created using a syntax almost identical to that used to create subroutines in packages. You may optionally specify the properties and signature of the method.

Methods are the principle way to define the behavior of a class. A large number of later recipes describe the behavior of methods in more detail.


Log In to Comment


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