txt: ## does.md
  does
  
  Combined from primary sources listed below.
  
  # [In Type system](#___top "go to top of document")[§](#(Type_system)_trait_does "direct link")
  
  See primary documentation
  [in context](/language/typesystem#trait_does)
  for **trait does**.
  
  The trait `does` can be applied to roles and classes providing compile time mixins. To refer to a role that is not defined yet, use a forward declaration. The type name of the class with mixed in roles does not reflect the mixin, a type check does. If methods are provided in more than one mixed in role, the method that is defined first takes precedence. A list of roles separated by comma can be provided. In this case conflicts will be reported at compile time.
  
  ```raku
  role R2 {...};
  role R1 does R2 {};
  role R2 {};
  class C does R1 {};
  
  say [C ~~ R1, C ~~ R2];
  # OUTPUT: «[True True]␤»
  ```
  
  For runtime mixins see [but](/language/operators#infix_but) and [does](/language/operators#infix_does).
  
  # [In Mu](#___top "go to top of document")[§](#(Mu)_routine_does "direct link")
  
  See primary documentation
  [in context](/type/Mu#routine_does)
  for **routine does**.
  
  ```raku
  method does(Mu $type --> Bool:D)
  ```
  
  Returns `True` if and only if the invocant conforms to type `$type`.
  
  ```raku
  my $d = Date.new('2016-06-03');
  say $d.does(Dateish);             # OUTPUT: «True␤»    (Date does role Dateish)
  say $d.does(Any);                 # OUTPUT: «True␤»    (Date is a subclass of Any)
  say $d.does(DateTime);            # OUTPUT: «False␤»   (Date is not a subclass of DateTime)
  
  ```
  
  Unlike [`isa`](/routine/isa#(Mu)_routine_isa), which returns `True` only for superclasses, `does` includes both superclasses and roles.
  
  ```raku
  say $d.isa(Dateish); # OUTPUT: «False␤»
  
  ```
  
  Using the smartmatch operator [~~](/routine/~~) is a more idiomatic alternative.
  
  ```raku
  my $d = Date.new('2016-06-03');
  say $d ~~ Dateish;                # OUTPUT: «True␤»
  say $d ~~ Any;                    # OUTPUT: «True␤»
  say $d ~~ DateTime;               # OUTPUT: «False␤»
  ```
  
  # [In Operators](#___top "go to top of document")[§](#(Operators)_infix_does "direct link")
  
  See primary documentation
  [in context](/language/operators#infix_does)
  for **infix does**.
  
  ```raku
  sub infix:<does>(Mu $obj, Mu $role) is assoc<non>
  ```
  
  Mixes `$role` into `$obj` at runtime. Requires `$obj` to be mutable.
  
  Similar to [but](/routine/but) operator, if `$role` supplies exactly one attribute, an initializer can be passed in parentheses.
  
  Similar to [but](/routine/but) operator, the `$role` can instead be an instantiated object, in which case, the operator will create a role for you automatically. The role will contain a single method named the same as `$obj.^name` and that returns `$obj`:
  
  ```raku
  my $o = class { method Str { "original" } }.new;
  put $o;            # OUTPUT: «original␤»
  $o does "modded";
  put $o;            # OUTPUT: «modded␤»
  ```
  
  If methods of the same name are present already, the last mixed in role takes precedence.
  