Chris Shawmail (E-mail) writes: > I'm still digesting the vocabulary thread, but while I do, let me ask a > question that's probably crystal clear to everyone else. > > Do roles act as a form of mix-in, as Ruby modules may, and Objective-C > protocols do? > > Would the following two snippets be at all equivalent?
Probably, depending on what's in the eventual definition of Foo. Roles are quite similar to mixins (as the Traits paper said that they were inspired by mixins), but they're distinctly not the same. For one, one role's methods don't silently override another's. Instead, you get, er, role conflict and you have to disambiguate yourself. For two, you can attach new roles to an object at runtime (I don't know if you can do this with mixins, actually). > # Perl6 > role Talk { > method say_hello { > print "Hello world!\n" > } > } > > class Foo does Talk { ... } > > Foo.new.say_hello; > > # Ruby > module Talk > def say_hello > puts "Hello world!" > end > end > > class Foo > include Talk > end > > Foo.new.say_hello Luke