# Traits1.9.0 released

**URL:** <https://www.ruby-forum.com/t/traits1-9-0-released/133693>\
**Category:** Ruby\
**Created:** [April 2, 2008, 5:30pm UTC](https://www.ruby-forum.com/t/traits1-9-0-released/133693 "2008-04-02T17:30:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![flatekmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e8c25b/32.png) [@flatekmonkey](https://www.ruby-forum.com/u/flatekmonkey)\
**Post date:** [April 2, 2008, 5:30pm UTC](https://www.ruby-forum.com/t/traits1-9-0-released/133693/1 "2008-04-02T17:30:50Z")

</div>

Hi list

I just released an implementation of traits tailor made for Ruby1.9.

[http://rubyforge.org/projects/ruby-traits/](http://rubyforge.org/projects/ruby-traits/)

You can still use this library with Ruby1.8 but you cannot pass blocks  
to behavior which  
pretty much restricts its usefulness.

- This implements traits in the strict sense of their definition  
here:  
[http://portal.acm.org/ft\_gateway.cfm?id=1028771&type=pdf&coll=GUIDE&dl=GUIDE&CFID=7912496&CFTOKEN=77115102](http://portal.acm.org/ft_gateway.cfm?id=1028771&type=pdf&coll=GUIDE&dl=GUIDE&CFID=7912496&CFTOKEN=77115102)

They obey the flattening property, using a trait is exactly as defining  
its methods inline, no modules are used and inheritance is unchanged.  
All trait combination rules are obeyed (associative, communative, e.g.)

The main purpose of pure-traits is to play around with them and to see  
the  
benefits and shortcomings of traits based design.

The syntax has changed, again inspired by Factes, trait aliasing is done  
via #\* now, thus traits aliased and combined can be expressed more  
naturally:  
t1 \* { :a =\> :t1\_a } + t2 \* { :a =\> :t2\_a }  
works now as expected.

In addition to the traditional trait operations +, - and \*, I have  
implemented & to allow of selective usage of behavior.  
I believe that the usage of this is normally a bad sign for the design  
but sometimes it might be a handy feature.

Behavior in a trait is defiend with the message method accespting a  
name and a block.  
Only when a trait is used by a class or object the behavior is defined  
as a method.  
Modules do not play any role in this version.

The following examples shall just give a quick look and feel, please  
refer to test/test-examples.rb  
which is somehow written in tutotial style.  
t = trait {  
message :a do @a=42 end  
message :b do |x,&blk| blk.call( x \* @a ) end  
}  
class C  
use t  
end

c=C.new.a  
c.b(42) do |x| puts x end —\> 1764

class C  
use t, trait { message :a do 42 end }  
end  
C.new.a —\> Trait::TraitsConflict

u = Trait::new do  
message :c do a+b(1){|x| x} end  
end

(t + u).to\_object.c → 84

Enjoy  
Robert
