ActiveRecord
is a ClassActiveRecord::Migration
is a module[5.2]
is array with oneFloat
But what means ActiveRecord::Migration[5.2]
?
ActiveRecord
is a Class ActiveRecord::Migration
is a module [5.2]
is array with one Float
But what means ActiveRecord::Migration[5.2]
?
Ruby allows you to define a []
method like this:
class Foo
def [](bar)
puts bar
end
end
Then you can do:
x = Foo.new
foo["baz"] # prints baz
This also works with a class method []
, not just with an instance one:
class Foo
def self.[](bar)
puts bar
end
end
Now Foo["a"]
prints a.
Rails is taking advantage of this through this code here: https://github.com/rails/rails/blob/66cabeda2c46c582d19738e1318be8d59584cc5b/activerecord/lib/active_record/migration.rb#L543
So the [5.2]
in your example is not an array with a float inside, it's a call to the ActiveRecord::Migration.[]
method with 5.2 as the argument.