lib/polynomials/point.rb in polynomials-0.4.3 vs lib/polynomials/point.rb in polynomials-0.4.4

- old
+ new

@@ -2,17 +2,18 @@ class Point include Comparable attr_accessor :x, :y alias to_f x - def self.inherited(subclass) - self.class_eval do - define_method :"#{subclass.name.demodulize.underscore}?" do - self.is_a? subclass + %w{Extremum Root InflectionPoint}.each do |special_point| + self.class_eval do + define_method :"#{special_point.underscore}?" do + self.is_a? Polynomials.const_get(special_point) end end end + def initialize(x,y) @x,@y = x,y end def to_s @@ -66,7 +67,15 @@ super(x,0) end end class InflectionPoint < Point + end + + [:maximum,:minimum].each do |kind_of_extremum| + const_set(kind_of_extremum.to_s.capitalize, Class.new(Extremum) do + def initialize(x,y) + super x,y,kind_of_extremum + end + end) end end