Hi,
Does anyone know how to create a ruby class in runtime?
ex:
class Parent
def…
def…
end
in runtime, we want to create a class “child” inherited from “parent”,
it is possible?
thanks you very much
sayoyo
Hi,
Does anyone know how to create a ruby class in runtime?
ex:
class Parent
def…
def…
end
in runtime, we want to create a class “child” inherited from “parent”,
it is possible?
thanks you very much
sayoyo
[email protected] wrote:
in runtime, we want to create a class “child” inherited from “parent”,
it is possible?
Yup, it is:
child = Class.new(parent) do
def method(arg)
…
end
define_method(dynamic_name) do |arg|
…
end
const_set(:Constant, 5)
end
[email protected] wrote:
in runtime, we want to create a class “child” inherited from “parent”,
it is possible?
klass = Class.new Parent
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs