Rails模型中的两级命名间距

问题描述 投票:0回答:1

如果我在我的Rails里有这样的东西。model 这两者有什么不同?

class A::B::C < ApplicationRecord
  ....
end
module A
  module B
    class C < ApplicationRecord
    ....
    end
  end
end

谢谢你的回答。

ruby-on-rails namespaces rails-activerecord
1个回答
0
投票

两者是一样的。

module A
  module B
    class C 
        def test
         puts "hii"
        end
    end
  end
end

ob = A::B::C.new()
ob.test  => hi

class A::B::C
  def testing
    puts "hello"
  end
end

ob1 = A::B::C.new()
ob1.testing  => hello

希望能弄清楚这个概念...

© www.soinside.com 2019 - 2024. All rights reserved.