Re-define File::dirname ruby method
Posted
by jrhicks
on Stack Overflow
See other posts from Stack Overflow
or by jrhicks
Published on 2009-09-30T02:47:13Z
Indexed on
2010/05/23
16:00 UTC
Read the original article
Hit count: 230
ruby
I'm trying to redefine the File.dirname method to first change %20s to spaces. But the following gives me an error
class File
old_dirname = instance_method(:dirname)
define_method(:dirname) { |s|
s = s.gsub("%20"," ")
old_dirname.bind(self).call(s)
}
end
This trhows a NameError exception: undefined method 'dirname' for class 'File'
What is the right way to do this?
© Stack Overflow or respective owner