I want to extend ruby's file class, but it doesn't work.
The ruby version is 2.0.0p648.
http://qiita.com/umanoda/items/33613b94ccabf7b1f851
I tried using this article as a reference.
I want 'extend' to be displayed, but the open method returns normal operation
Could someone please teach me?
class File
alias_method:__open__, —open
default()
'extend'
end
end
pFile.open('test.txt')
#<File:test.txt>
Thank you for your cooperation.
ruby
Because you overwrite the class method, you will have to define the class method instead of the instance method.
class File
class<<self
alias_method:__open__, —open
end
def self.open(*args)
'extend'
end
end
pFile.open('test.txt')
© 2024 OneMinuteCode. All rights reserved.