(edited to make question more specific)
I would like to know if it's possible to execute a singleton method in the context of another object as in the following example:
class A
def initialize
@foo = 'foo'
end
end
def A.singleton(*args)
puts 'in singleton'
puts @foo
end
A.new.instance_eval &A.method(:singleton)
# output is:
# - in singleton
# desired output:
# - in singleton
# - foo