In Ruby on Rails 5.2, migration files contain a class that looks like this.
class MyMigration < ActiveRecord::Migration[5.2]
I know that the [5.2] syntax is specifying what version of rails the migration targets, but I don't understand how this works. Migration[5.2] is not a valid Ruby class name.
What is this square bracket syntax, and how is it not causing ruby syntax errors?
Ruby objects can have [] methods. They are used in the Array class, but any class can implement them.
def []()
...
end
Since classes are full objects, they too can have square bracket methods.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With