0
1

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 3 years have passed since last update.

railsでruby組み込みライブラリを拡張する

Posted at

任意のフォルダに拡張ファイルを配置

lib/core_ext/string.rb
class String
  def hoge
    self+" fuga"
  end
end

'config/initializers'配下に以下のようなファイルを配置

config/initializers/core_ext.rb
Dir.glob(File.join(Rails.root, 'lib', '*_ext', '*.rb')) do |file|
  load file
end

これで Strinig.hoge が使えるようになった。
以下がとても参考になった
https://dev.classmethod.jp/articles/ruby-object-to-boolean/

0
1
1

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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?