Klein Mioke
Klein Mioke

Reputation: 1352

How to call `pod` or 'target' in another script

Now I have a function that defined in another ruby file, and I want to call target and pod function dynamically. like:

module MyModule

def MyModule.some_function 
  # do something and then
  target "#{result_name}" do 
    pod 'AFNetworking'
  end 
end 

end

In podfile:

required './some_function'

MyModule.some_function

Is that available?

Edit: Adding Module for my script file, and when I run pod install and there's an error says unknown method pod in module MyModule

Upvotes: 1

Views: 158

Answers (1)

Andrés
Andrés

Reputation: 624

You can use define_method :"#{result_name}" do ... end to do it

For example

# inside foo.rb
def foo
    define_method :bar do
        puts "bar"
    end
end

#inside main.rb
require_relative "foo" # require_relative  automatically set ./file

foo
bar # puts "bar"

Upvotes: 1

Related Questions