Prevent inheritance in Ruby -
I am trying to explain how to avoid the legacy of a method in all the subclasses. Currently I'm trying with such code:
puts square maternity calls in class "# {self.class} phoned" end-protected def phone_keys "called children" end The end class puts the child; Mother's End
But without any consequence, as I am getting such an error: & lt; Top (required) & gt; ': Safe Mode' phone_kids' # & lt; 0x604da0 & gt; (NoMethodError)
. Can you please briefly tell me how works in Ruby?
Thanks in advance!
// Edit:
I am getting this error with this code:
child = child.No mother = mother. Mother.phone_kids
If you need to do this, it means that If you are not using the heritage correctly, if D gets the class C , then it should be a "one" relationship: every C < / Em> is a D . Since every child is not a mother, the use of heritage is bad in this case.
Here is how you can show parents and children in Ruby with the use of only one class:
class person attr_accessor: name attr_accessor : Beg to children (name) @ name = name = child = [] end df phone_kids @ children.each {| C | The C.phone} enddef puts the phone "# {@ name}" and end
, now to answer the basic question. If you want to prevent the child
class from being inherited by the phone_kids
method, then you can do something like this:
class mater Def Self-inherited (Claes) Claes. ((Define_method: phone_kids), noMethodError End And Diff Increases Phone_Kids "Phoneed Children" End And Class Children And Lieutenant; Mother End Mom.new.phone_Kids # = & gt; Children Called.newphone_kids # = & Gt; NoMethodError
Comments
Post a Comment