Beginner Ruby language

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)

[Done] exited with code=1 in 4.463 seconds

I never had this problem before…

It should be in that order:
image

You get the mentioned error if you do:

It’s telling you you have an error in line 1 of your program, most likely a typo. Cut and paste the code here. Use the markup

```ruby
(v1 = 10)
```
so that it formats like

(v1 = 10)

and we can all read it more easily

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:

v1 = 10
puts v1

Hi guys, thanks for your answer!
But I just found the error!!
After remove the number one (on top of screen) the problem was fixed :grin:

1 Like

Yes. Technically what was happening:

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.