N
Nit Khair
I am trying to extend a class developed by someone else (its from the
ncurses-ruby lib). I need to add some fields and methods to it.
1. I tried directly extending it the usual way.
class MyForm < FORM
However, all attempts to access my methods would give a NoMethodError
on the base class Ncurses::FORM.
2. I then looked up the source and copied the following *on top* of my
class MyForm.
module Form
class FORM
attr_reader :user_object
def user_object=(obj)
@user_object = obj
end
end
end
I changed user_object to "my_fields". This approach works, but means i
cannot actually extend the class. I need a heirarchy below this each
adding its methods and data.
Now I am wondering whether my approach is wrong. Is the class
locked/final in some way?
I am aware of an alternative appoach: create an instance of FORM in a
class (no more inheritance). Use method_missing to call methods of
original class. However, before i make changes, would like to understand
if I am doing something wrong here.
Thanks.
ncurses-ruby lib). I need to add some fields and methods to it.
1. I tried directly extending it the usual way.
class MyForm < FORM
However, all attempts to access my methods would give a NoMethodError
on the base class Ncurses::FORM.
2. I then looked up the source and copied the following *on top* of my
class MyForm.
module Form
class FORM
attr_reader :user_object
def user_object=(obj)
@user_object = obj
end
end
end
I changed user_object to "my_fields". This approach works, but means i
cannot actually extend the class. I need a heirarchy below this each
adding its methods and data.
Now I am wondering whether my approach is wrong. Is the class
locked/final in some way?
I am aware of an alternative appoach: create an instance of FORM in a
class (no more inheritance). Use method_missing to call methods of
original class. However, before i make changes, would like to understand
if I am doing something wrong here.
Thanks.