A
Alexey Petrushin
Hello!
I'm using method_missing to create DSL, the problem is that Kernel.xxx
methods are interferes with it.
How this issue can be solved?
It seems that one solution is to explicitly define all global methods
(p, select, ...) on the target class for method_missing.
But i hope there is more elegant solution . Maybe some trick with
sandboxes?
CODE:
class Parameters # < BlankSlate
attr_reader :result
def initialize &block
@result = {}
instance_eval &block
end
def method_missing m, *p
@result[m] = *p
end
end
describe do
it do
hash = Parameters.new do
one 1
select1 'Select' # <= Problem here, it calls Kernel.select
end.result
hash.should == {ne => 1, :select1 => 'Select'}
end
end
I'm using method_missing to create DSL, the problem is that Kernel.xxx
methods are interferes with it.
How this issue can be solved?
It seems that one solution is to explicitly define all global methods
(p, select, ...) on the target class for method_missing.
But i hope there is more elegant solution . Maybe some trick with
sandboxes?
CODE:
class Parameters # < BlankSlate
attr_reader :result
def initialize &block
@result = {}
instance_eval &block
end
def method_missing m, *p
@result[m] = *p
end
end
describe do
it do
hash = Parameters.new do
one 1
select1 'Select' # <= Problem here, it calls Kernel.select
end.result
hash.should == {ne => 1, :select1 => 'Select'}
end
end