I wrote the following code in a file 1_arithmetic.rb
:
def arithmetic1(n)
(n * 5) - 20
end
Using the gem tool rake
, I typed this into the console:
rake 1_arithmetic.rb:arithmetic1(5)
Then, I got an error message that reads:
syntax error near unexpected token `('
Does anyone know where I might have done wrong? Or is the problem the way I used rake
?
I believe rake can only be used with a rake task. You could create a rake task that then calls your method.
require './1_arithmetic.rb'
task :arithmetic, [:n] => [:environment] do |t, args|
arithmetic1(args[:n])
end
You would then call the task using
rake arithmetic[5]
reference: How can I run a ruby class from rake file?
reference: How to pass command line arguments to a rake task