Extending Rails Models

Rails models come with specific built-in methods:

Appointment.new Appointment.find(1) 

How to add additional methods to Appointment ? Apparently, this was not done by adding methods to app/models/appointment.rb . This adds the methods to the Appointment instance, but I want to add the methods to the Appointment myself. How to do it?

+4
source share
2 answers
 def self.some_method #do stuff end 
+12
source

Marking the answer is definitely right, but when defining class methods, you will also see the following syntax:

 class Appointment class << self def method1 # stuff end def method2 # stuff end def method3 # stuff end end end 
+3
source

Source: https://habr.com/ru/post/1334779/


All Articles