LoginSignup
7
3

More than 5 years have passed since last update.

【rails】【デバッグ】railsコンソールでモジュール内のクラスメソッドの呼び出し方法

Last updated at Posted at 2013-10-17

moduleのソース

module G08M11

     class Test1Class

          def test1method
               return 222
          end
     end
end

railsコンソールの呼び出し

rails c

a = G08M11::Test1Class.new
a.test1method

実行結果:

=> 222 



ポイント
- インスタンス化
- railsコンソールで呼び出す際はモジュールの後は「::」が付く


追記
結合テスト時に機能によっては「self.」があることで外部から呼び出せないなどで
途中で落ちる場合があります。
そのため、単体で確認後は結合でも確認することをおすすめします。

7
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
3