mercredi 16 novembre 2016

Ruby DSL nested constructs

I am using the following code to enforce context of DSL nested constructs. What are the other ways of achieving the same functionality?

def a &block
  p "a"
  def b &block
    p "b"
    def c &block
      p "c"
      instance_eval &block
    end 
    instance_eval &block
    undef :c
  end 
  instance_eval &block 
  undef :b
end 
# Works
a do
  b do
    c do
    end
  end
end

# Doesn't Work 
b do
end
c do
end

Source

Aucun commentaire:

Enregistrer un commentaire