You just open the class and add methods . If you know the name of the class and where it is located in the module hierarchy, then you simply create another file that defines the same class, and start adding methods. Since this is the same class name, methods will be added to another class.
This probably looks like what you did with Devise.
So, if I have a class Barin a gem, and it is inside a module namedFoo
module Foo
class Bar
def foobar
'foobar!'
end
end
end
To add to this class a method called bazwithout changing the source code of gem, then in the application just create a new file, declare the class inside its module again and start adding material.
module Foo
class Bar
def baz
'foobar baz!'
end
end
end
> f = Bar.new
> f.foobar
=> 'foobar!'
> f.baz
=> 'foobar baz!'
, .
baz Bar , Bar. , Bar, , Bar, .
class NewClass < Foo::Bar
def baz
'foobar baz!'
end
end
> nc = NewClass.new
> nc.foobar
=> 'foobar!'
> nc.baz
=> 'foobar baz!'