[Ann] traits-1.9.1 released

R

Robert Dober

Hi list

motivated by a recent discussion on this list and in order to be
functionally compatible with #is_a? for modules I have added
Object#behaves_like?. I did not want to overload Object#is_a? because
traits do not really semantically provide the notion of inheritance.
An important difference to is_a? or Module#=== is that
Object#behaves_like? will always reflect the current state of the
object and the trait in question even if they were
dynamically changed.

E.g.
t = trait {
message :a do :a end
}
o = t.to_object
t.message :b do :b end
o.behaves_like? t # --> false
class << o
def b; 42 end
end
o.behaves_like? t # --> true


You can use Object#behaves_like? with all objects that respond to a
message get_message_names
if it returns an Enumerable yielding strings and symbols to #each, but
of course it is primarily
designed for traits ;).

Enjoy
Robert

http://rubyforge.org/frs/?group_id=4642
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top