I’m using Ruby 1.9.2. For example i’ve got class :
class Test
def ==(param)
# some process
end
def bar(param)
puts "foo bar #{param}"
end
end
I can invoke bar method using :
Test.new.instance_eval{ bar 'celona' }
But i cannot execute == method from block like
Test.new.instance_eval{ == "foo" }
i’ve got syntax error, unexpected tEQ
The following worked for me:
The solution really depends on your use case.
Edit The same holds true for when you instantiate a class.
You can also use
selfI am not entirely sure of the reason, but I would guess that the
==method required an explicit callee and it can’t inferself