Hiding kernel methods from DSL

Hi,

I’ve implemented a DSL type system that uses instance_eval. I register
properties in and then use method_missing to route the missing method
calls through to the properties. My problem is that I want a property
called ‘test’ but rather than go through to method_missing its calling
Kernel.test (which I didn’t know existed). Is there a way of making it
so that the kernel methods are not visible when I call instance_eval? Or
is there a way of creating a class such that it doesn’t inherit Kernel?

Cheers,
James

Maybe you should try to undef Kernel#test in class where this methods
are implemented, but I haven’t tried this idea, so this may not work,
but why not to try?


Yuriy Plugatariov
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)

Answering my own question. My DSL objects should subclass BasicObject.

From: ruby-talk [mailto:[email protected]] On Behalf Of
James F.
Sent: 09 April 2014 10:04
To: [email protected]
Subject: Hiding kernel methods from DSL

Hi,

I’ve implemented a DSL type system that uses instance_eval. I register
properties in and then use method_missing to route the missing method
calls through to the properties. My problem is that I want a property
called ‘test’ but rather than go through to method_missing its calling
Kernel.test (which I didn’t know existed). Is there a way of making it
so that the kernel methods are not visible when I call instance_eval? Or
is there a way of creating a class such that it doesn’t inherit Kernel?

Cheers,
James

On Wed, Apr 9, 2014 at 11:04 AM, James F.
[email protected] wrote:

of creating a class such that it doesn’t inherit Kernel?
That’s what BasicObject is for:

2.0.0-p195 :025 > class MyObject < BasicObject
2.0.0-p195 :026?> def method_missing meth, *args, &blk
2.0.0-p195 :027?> ::Kernel.puts “#{meth} called with #{args}”
2.0.0-p195 :028?> end
2.0.0-p195 :029?> end
=> nil
2.0.0-p195 :030 > MyObject.new.hello
hello called with []
=> nil
2.0.0-p195 :031 > MyObject.new.test
test called with []

Jesus.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs