F
Francis Hwang
So maybe some of you language wizards out there can help me with this:
Is there a way to define a method that aliases some external method
without assigning that method to a global in the first place?
The example is the code below: For mockfs/override.rb, I'm undefining
File, but want to keep File.join.
$join_method = File.method :join
Object.send( :remove_const, :File )
module File
def self.join( *args )
$join_method.call *args
end
def self.method_missing( symbol, *args )
MockFS.file.send( symbol, *args )
end
end
This works, but then I'm leaving a global variable just sitting around.
Is there a better way to do this?
Francis Hwang
http://fhwang.net/
Is there a way to define a method that aliases some external method
without assigning that method to a global in the first place?
The example is the code below: For mockfs/override.rb, I'm undefining
File, but want to keep File.join.
$join_method = File.method :join
Object.send( :remove_const, :File )
module File
def self.join( *args )
$join_method.call *args
end
def self.method_missing( symbol, *args )
MockFS.file.send( symbol, *args )
end
end
This works, but then I'm leaving a global variable just sitting around.
Is there a better way to do this?
Francis Hwang
http://fhwang.net/