J
Jim Freeze
Hi
I am fine tuning a DSL and came across the situation
where I needed a method with the name of 'module'.
In my previous revision of the DSL, I did the following:
------------
class C
def initialize
yield self
end
def module
puts "in C#module"
end
end
-------------
The user code would then look like:
C.new do |c|
c.module
end
But, I didn't really like requiring (or explaining)
why the 'c.' was required. So I rewrote the class to be:
------------
class C
def initialize(&block)
instance_eval &block
end
def module
puts "in C#module"
end
end
-------------
But, when a method name is called that is dear to Ruby heart,
like 'module', an error is generated:
C.new do
module
end #=> syntax error
Is there any way to have get the effect of the above
c.module
with the instance_eval?
Thanks
I am fine tuning a DSL and came across the situation
where I needed a method with the name of 'module'.
In my previous revision of the DSL, I did the following:
------------
class C
def initialize
yield self
end
def module
puts "in C#module"
end
end
-------------
The user code would then look like:
C.new do |c|
c.module
end
But, I didn't really like requiring (or explaining)
why the 'c.' was required. So I rewrote the class to be:
------------
class C
def initialize(&block)
instance_eval &block
end
def module
puts "in C#module"
end
end
-------------
But, when a method name is called that is dear to Ruby heart,
like 'module', an error is generated:
C.new do
module
end #=> syntax error
Is there any way to have get the effect of the above
c.module
with the instance_eval?
Thanks