A
A
Alexander Grishin2016-12-26 14:14:27
Ruby on Rails
Alexander Grishin, 2016-12-26 14:14:27

Is it possible to require files inside methods like this?

def opop
  require './SomeClass.rb'
end
opop

Is it possible to require files inside methods?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Artem Gladyshev, 2016-12-28
@fairoj

Nothing prevents you from doing this, but it is not very good in terms of code organization.
Also, you don't need to specify the .rb file extension, require will do it for you.
A file with a relative path is better to load like this:
require File.expand_path('../someclass', __FILE__)

B
Bratela, 2016-12-29
@Bratela

Or like this:

require_relative 'someclass'
opop #вызов метода прописаный в someclass.rb

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question