behaves
behaves copied to clipboard
Allow the behaviour class to expose which class its behaving like.
class Animal
extend Behaves
implements :method_one
end
class Dog
extend Behaves
behaves_like Animal
def method_1
"hello"
end
end
When we do this:
dog = Dog.new
dog.behaves_like # returns Animal
I may have a collection of objects, and i will like to do some operations on them. Hence i can decide if these object behaves_like a certain type, i want perform an operation which is related to this class, since it will definitely define the method its required to implement and the injected behavior.
👋 nice idea, one thing to keep in mind when implementing is also the fact that multi-behaviors are a thing, so expected return should probably be an array.
Also, not sure if we want to name the method behaves_like
, might get really confusing