Hey guys!
I am a beginner student in Ruby language.
Could you help me with a question?
When I start a variable (v1 = 10) and execute the command line puts v1 the Ruby is returning the error:
[Running] ruby “c:\ruby\exercicios_logica_programacao.rb”
c:/ruby/exercicios_logica_programacao.rb:1:in <main>': undefined method v1=’ for 1:Integer (NoMethodError)
Might I ask what language you are more accustomed to using? There is no need for parentheses when assigning variables in Ruby. (v1 = 10) should just be v1 = 10 no need for parentheses. With the parentheses, Ruby is expecting a method (and the error message tells you that). It is expecting something like: a_method(v1 = 10) Try instead:
1 is an integer. Everything is an object in Ruby, so when you put a dot after it, the interpreter expects a method call, like 1.times or 1.to_s
Your 1. is followed by #, which comments out the rest of the line. And the next 13 lines are blank or comments too. The interpreter is still waiting for the method call after the dot, and the first thing he finds is the v1= on line 16.
The Integer class doesn’t have a v1= method, so it throws NoMethodError from the statement that started way back on line 1 of the file.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.