behaves icon indicating copy to clipboard operation
behaves copied to clipboard

Allow the behaviour class to expose which class its behaving like.

Open NavindrenBaskaran opened this issue 5 years ago • 1 comments

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.

NavindrenBaskaran avatar Jun 18 '19 15:06 NavindrenBaskaran

👋 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

edisonywh avatar Jun 18 '19 16:06 edisonywh