M
M
Mimuss2019-12-12 20:38:20
ruby
Mimuss, 2019-12-12 20:38:20

Hook to create a class in Ruby?

Let's say there is a class in it there is initialization and all that. After creating the class, I need to call a hook with arbitrary code that calls the methods of the class, but on the condition that I cannot write this in the class description itself.
And here I mean not the creation of an instance of the class, but the initialization of the class itself.
For example:

class SomeClass < ActiveRecord
  call_some_method('bla_bla_bla')
  def some_method
    return 1
  end
  # end of initialization
end

Sounds weird, but I really need it.
Is there such a way?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Omich, 2019-12-17
@omichkun

I haven’t seen hooks for creating a class, but you can try to do it through the include/extend of the module, or through inheritance. https://medium.com/rubycademy/metaprogramming-ruby...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question