Nonlinear oscillators are widely used in biology, physics and engineering for modeling and control. They are interesting because of their synchronization properties when coupled to other dynamical systems. In this paper, we propose a learning rule for oscillators which adapts their frequency to the frequency of any periodic or pseudo-periodic input signal. Learning is done in a dynamic way: it is part of the dynamical system and not an offline process. An interesting property of our model is that it is easily generalizable to a large class of oscillators, from phase oscillators to relaxation oscillators and strange attractors with a generic learning rule. One major feature of our learning rule is that the oscillators constructed can adapt their frequency without any signal processing or the need to specify a time window or similar free parameters. All the processing is embedded in the dynamics of the adaptive oscillator. The convergence of the learning is proved for the Hopf oscillator, then numerical experiments are carried out to explore the learning capabilities of the system. Finally, we generalize the learning rule to non-harmonic oscillators like relaxation oscillators and strange attractors.