What's the preferred method to add module functionality to library ruby code?
Consider the following:
module MyExceptions
class SomethingBadHappenedTheLibarayDesignerDidntConsider < StandardError; end
end
How can I add MyExceptions
module to a class that I don't control?
Update, in my_library_class_exceptions.rb
I did:
class LibraryClass
include MyExceptions
end
module MyExceptions
class SomethingBadHappenedTheLibarayDesignerDidntConsider < StandardError; end
end
But the console returns: NameError: uninitialized constant LibraryClass::MyExceptions
MyExceptions
should be in "my_exceptions.rb". Where have you put this file? – d11wtq Oct 20 '11 at 0:40Samurai
, so I put all the code listed in my update in a empty filed called:app/models/samurai.rb
– SooDesuNe Oct 20 '11 at 1:07MyExceptions
andMyExceptions
is not a known constant, auto-loading kicks in and a file namemy_exceptions.rb
is looked for. You'll either have to include the file manually, or name it according to its contents. – d11wtq Oct 20 '11 at 3:42