5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ruby 外部モジュール読み込み方法

5
Posted at

rubyで外部ファイルを外部モジュールとして読み込む方法

require 'hoge'

これをすると、読み出した側のスクリプトに展開される。
もし、hoge.rb にモジュールが定義されているならば、

include 'home_moudle'

を実行しなければいけない

補足
module Zozom
  def hello(name)
    puts "hello, #{name}"
  end
 
  def double(num)
    puts num * 2
  end
 
  module_function :hello, :double
end

こうすることで、include "Zozom"をすることなく、

Zozom.hello "hoge"
# => hello, hoge

のように読み出すことができる。

参考文献

5
6
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
5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?