I am trying to write a DSL that allows me to do
Policy.name do
author "Foo"
reviewed_by "Bar"
end
The following code can almost process it:
class Policy
include Singleton
def self.method_missing(name,&block)
puts name
puts "#{yield}"
end
def self.author(name)
puts name
end
def self.reviewed_by(name)
puts name
end
end
By defining my method as class methods (self.method_name), I can access it using the following syntax:
Policy.name do
Policy.author "Foo"
Policy.reviewed_by "Bar"
end
If I remove the “I” from the method names and try to use my desired syntax, then I get the error “Method not found” in the main one, so it could not find my function before the module core. Ok, I understand the error. But how can I fix this? How can I fix my class so that it works with my desired syntax?
source
share