# Ho un problema (sono uno nuovo al linguaggio che lo sta imparando)

**URL:** <https://www.ruby-forum.com/t/ho-un-problema-sono-uno-nuovo-al-linguaggio-che-lo-sta-imparando/252492>\
**Category:** IT\
**Created:** [May 27, 2019, 6:38pm UTC](https://www.ruby-forum.com/t/ho-un-problema-sono-uno-nuovo-al-linguaggio-che-lo-sta-imparando/252492 "2019-05-27T18:38:55Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![RenziShish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/71e660/32.png) [@RenziShish](https://www.ruby-forum.com/u/RenziShish)\
**Post date:** [May 27, 2019, 6:38pm UTC](https://www.ruby-forum.com/t/ho-un-problema-sono-uno-nuovo-al-linguaggio-che-lo-sta-imparando/252492/1 "2019-05-27T18:38:55Z")

</div>

Se scrivo  
file.open (“Leggimi” “r+”)  
mi da “traceback” e il programma (fatto con Command Prompt) non funziona.  
Qualcuno mi sa dire perchè?  
Ho messo la virgola e mi diceva errore, tra l’altro

---

<div class="post-metadata">

**Author:** ![SouravGoswami](https://www.ruby-forum.com/user_avatar/www.ruby-forum.com/souravgoswami/32/2543_2.png) [@SouravGoswami](https://www.ruby-forum.com/u/SouravGoswami)\
**Post date:** [June 8, 2019, 8:20pm UTC](https://www.ruby-forum.com/t/ho-un-problema-sono-uno-nuovo-al-linguaggio-che-lo-sta-imparando/252492/2 "2019-06-08T20:20:49Z")

</div>

Hi, I am so sorry for not understanding Italian. But I may help you in English. And I am not going to bother you with an incorrect Google translation! So sorry for that ☹

## Anyways, Here’s the Correct Version of your Code 🍭

File.open(“Leggimi”, “r+”)

## Description 🗒

#### 1. `File` is a Class in Ruby:

```auto
File.class # => Class

```

#### 2. open is a method of `File` class:

```auto
File.respond_to?(:open) # => true
# or
File.methods.include?(:open) # => true

```

#### 3. `()` and the `,` :

Because it’s Ruby you have a tonne of alternatives!

But the parentheses should be right after the `File.open`. If not it’s evaluated first and it really makes no sense to Ruby, and it raises SyntaxError !!  
You can even omit the `()` but you have to use the `,`.  
Nevertheless, you can call a method in many ways:

```auto
File.open('Leggimi', 'r+') # => #<File:Leggimi>
# Or
File.open 'Leggimi', 'r+' # => #<File:Leggimi>
# Or
File.method(:open).call('Leggimi', 'r+') # => #<File:Leggimi>
# Or
File.instance_method(:open).bind(File).('Leggimi', 'r+') # => #<File:Leggimi>

```

##### Suggestion: The `File.open` is not required! You can use `open` instead:

```auto
open('Leggimi', 'r+') # => #<File:Leggimi>
# Or even:
Kernel.open('Leggimi', 'r+') # => #<File:Leggimi> # But I don't suggest using it!

```

* * *

Hope this helps!

---

<div class="post-metadata">

**Author:** ![RenziShish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/71e660/32.png) [@RenziShish](https://www.ruby-forum.com/u/RenziShish)\
**Post date:** [June 8, 2019, 8:28pm UTC](https://www.ruby-forum.com/t/ho-un-problema-sono-uno-nuovo-al-linguaggio-che-lo-sta-imparando/252492/3 "2019-06-08T20:28:55Z")

</div>

Thank you. I’m gonna see if this helps. Anyway I didn’t use a comma because the command prompt said it was an error.

---

<div class="post-metadata">

**Author:** ![SouravGoswami](https://www.ruby-forum.com/user_avatar/www.ruby-forum.com/souravgoswami/32/2543_2.png) [@SouravGoswami](https://www.ruby-forum.com/u/SouravGoswami)\
**Post date:** [June 8, 2019, 8:32pm UTC](https://www.ruby-forum.com/t/ho-un-problema-sono-uno-nuovo-al-linguaggio-che-lo-sta-imparando/252492/4 "2019-06-08T20:32:48Z")

</div>

Yup, the error was putting the parentheses! I mean you have a space before the parentheses, and that doesn’t make it an argument to `File#open`. You can omit the parentheses too:

```auto
File.open 'Leggimi', 'r+'

```

But if you put parentheses, don’t leave any space before!

The previous answer is updated! Please take a look!

---

<div class="post-metadata">

**Author:** ![RenziShish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/71e660/32.png) [@RenziShish](https://www.ruby-forum.com/u/RenziShish)\
**Post date:** [June 9, 2019, 11:56am UTC](https://www.ruby-forum.com/t/ho-un-problema-sono-uno-nuovo-al-linguaggio-che-lo-sta-imparando/252492/5 "2019-06-09T11:56:51Z")

</div>

That doesn’t work either. Perhaps if I cancel the last version of Ruby (2.6) that I installed with 2.5 to update it, I’ll resolve the problem, because I read somewhere that the last version is bugged. I’ll cancel both versions, that I’ll install 2.5. Sorry for my bad english.

---

<div class="post-metadata">

**Author:** ![SouravGoswami](https://www.ruby-forum.com/user_avatar/www.ruby-forum.com/souravgoswami/32/2543_2.png) [@SouravGoswami](https://www.ruby-forum.com/u/SouravGoswami)\
**Post date:** [June 9, 2019, 6:06pm UTC](https://www.ruby-forum.com/t/ho-un-problema-sono-uno-nuovo-al-linguaggio-che-lo-sta-imparando/252492/6 "2019-06-09T18:06:47Z")

</div>

Ruby is not bugged in such simple stuffs. Bugs sometimes lie in `Regexp` and these stuffs (and I once heard about it, it’s fixed now). I don’t know what you are writing wrong. The program in the question makes no sense, you used space and parentheses, then omitted the comma, and it raised SyntaxError - that’s a normal behaviour.

Ruby is not a magical programming language and will not understand whatever you are trying to do. Ruby has syntax. Ruby is a huge programming language, calling this simple SyntaxErrors as Ruby bug is like saying a BMW is bad because you can’t drive cars.

Anyways, I discussed may ways in the above posts. I have tested the code on many older Rubies, JRuby. Even crystal language will work with `File.open()`.

If you are using MRuby, then simply avoid everything I have told you.

Can you paste the code from the `File.open` to you are closing the file?

---

<div class="post-metadata">

**Author:** ![RenziShish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/71e660/32.png) [@RenziShish](https://www.ruby-forum.com/u/RenziShish)\
**Post date:** [June 10, 2019, 7:56pm UTC](https://www.ruby-forum.com/t/ho-un-problema-sono-uno-nuovo-al-linguaggio-che-lo-sta-imparando/252492/7 "2019-06-10T19:56:47Z")

</div>

Yes, I know that working with Ruby (as with other languages) is not just typing code and running it. But I tried to fix the bug for 2 weeks, and I tried every method on the Internet (and all the methods that worked for others didn’t work for me). Maybe if I cancel all the versions of Ruby and I install it again, it will work. The code that command prompt shows after running the program is only “Traceback”. How can I cancel Ruby from my computer (all the versions)?

---

<div class="post-metadata">

**Author:** ![SouravGoswami](https://www.ruby-forum.com/user_avatar/www.ruby-forum.com/souravgoswami/32/2543_2.png) [@SouravGoswami](https://www.ruby-forum.com/u/SouravGoswami)\
**Post date:** [June 10, 2019, 9:31pm UTC](https://www.ruby-forum.com/t/ho-un-problema-sono-uno-nuovo-al-linguaggio-che-lo-sta-imparando/252492/8 "2019-06-10T21:31:24Z")

</div>

Can you paste in the code here?

I don’t know, if there’s any installation problem… Personally speaking, I never had the issue on any of my systems (all are Linux), so I am ignorant about installation issue.

If you are not using MRuby, can you open up your IRB and type:

```auto
puts RbConfig::CONFIG.map { |v| v.join(' => ') }

```

This will show all the details! Also, note down the Ruby version. Can you please comment back?

If there’s no issue running the above code, then I think your installation is fine! Also, note that if you are using Windows (though I used only virtualmachine and never used bare metal windows), you may have problems with opening the file. I suggest you always use this following code to avoid `Errno::ENOENT` error:

```auto
PATH = File.dirname( __FILE__ ) # or $PROGRAM_NAME if you are not requiring it
File.open(File.join(PATH, 'Leggimi'), 'r+')

```

And this is really what I do, and I have seen many codes that use this.  
Please confirm the above results then we might understand what’s the real problem!

---

<div class="post-metadata">

**Author:** ![RenziShish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/71e660/32.png) [@RenziShish](https://www.ruby-forum.com/u/RenziShish)\
**Post date:** [June 17, 2019, 12:14pm UTC](https://www.ruby-forum.com/t/ho-un-problema-sono-uno-nuovo-al-linguaggio-che-lo-sta-imparando/252492/9 "2019-06-17T12:14:24Z")

</div>

Scusa se ti ho risposto ora, sono stato molto impegnato questo periodo con gli esami, dato che andavo ancora a scuola. Comunque proverò e ti dirò i risultati. Grazie per l’aiuto.

---

<div class="post-metadata">

**Author:** ![SouravGoswami](https://www.ruby-forum.com/user_avatar/www.ruby-forum.com/souravgoswami/32/2543_2.png) [@SouravGoswami](https://www.ruby-forum.com/u/SouravGoswami)\
**Post date:** [June 17, 2019, 6:42pm UTC](https://www.ruby-forum.com/t/ho-un-problema-sono-uno-nuovo-al-linguaggio-che-lo-sta-imparando/252492/10 "2019-06-17T18:42:04Z")

</div>

Sure! No worries. Let’s just follow my last answer!

---

<div class="post-metadata">

**Author:** ![RenziShish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/71e660/32.png) [@RenziShish](https://www.ruby-forum.com/u/RenziShish)\
**Post date:** [June 19, 2019, 10:10am UTC](https://www.ruby-forum.com/t/ho-un-problema-sono-uno-nuovo-al-linguaggio-che-lo-sta-imparando/252492/11 "2019-06-19T10:10:40Z")

</div>

C’è un problema nel funzionamento del codice, infatti il command prompt dice che non lo riconosce come comando, ma i comandi come “$gem install” sono riconosciuti.

---

<div class="post-metadata">

**Author:** ![SouravGoswami](https://www.ruby-forum.com/user_avatar/www.ruby-forum.com/souravgoswami/32/2543_2.png) [@SouravGoswami](https://www.ruby-forum.com/u/SouravGoswami)\
**Post date:** [June 19, 2019, 7:09pm UTC](https://www.ruby-forum.com/t/ho-un-problema-sono-uno-nuovo-al-linguaggio-che-lo-sta-imparando/252492/12 "2019-06-19T19:09:09Z")

</div>

Can you access IRB?  
Just type:

```auto
irb

```

You already know, you will have a REPL like this:

 ![image](https://www.ruby-forum.com/uploads/default/original/2X/e/e44f77888a54737b2461537e378b8a52a40bac3a.png)

If irb isn’t recognized, there could be an installation problem. Also, if your ruby is MRuby, all the comments I made might not work. If your Ruby is MRI, JRuby, and older MRI like 2.3.8, then it should work…

---

<div class="post-metadata">

**Author:** ![RenziShish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/71e660/32.png) [@RenziShish](https://www.ruby-forum.com/u/RenziShish)\
**Post date:** [June 26, 2019, 1:05pm UTC](https://www.ruby-forum.com/t/ho-un-problema-sono-uno-nuovo-al-linguaggio-che-lo-sta-imparando/252492/13 "2019-06-26T13:05:34Z")

</div>

Scusami se ho risposto ora, sono stato molto impegnato con lo studio e gli esami fino a ieri, ora per fortuna sono finiti. Comunque, il risultato che ho ricavato scrivendo “irb” nel command prompt è:  
irb(main):001:0\>  
La mia versione di Ruby è 2.5 aggiornata con la versione 2.6

---

<div class="post-metadata">

**Author:** ![SouravGoswami](https://www.ruby-forum.com/user_avatar/www.ruby-forum.com/souravgoswami/32/2543_2.png) [@SouravGoswami](https://www.ruby-forum.com/u/SouravGoswami)\
**Post date:** [June 26, 2019, 5:25pm UTC](https://www.ruby-forum.com/t/ho-un-problema-sono-uno-nuovo-al-linguaggio-che-lo-sta-imparando/252492/14 "2019-06-26T17:25:01Z")

</div>

Sorry that I write in English. Hope your exams were good!  
However, if IRB is running, then Ruby installation is probably fine! Try running the above commands, if they run successful, I think your ruby installation is fine!

---

<div class="post-metadata">

**Author:** ![RenziShish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/71e660/32.png) [@RenziShish](https://www.ruby-forum.com/u/RenziShish)\
**Post date:** [June 26, 2019, 6:39pm UTC](https://www.ruby-forum.com/t/ho-un-problema-sono-uno-nuovo-al-linguaggio-che-lo-sta-imparando/252492/15 "2019-06-26T18:39:36Z")

</div>

I miei esami fortunatamente sono finiti. Ci proverò domani di sicuro, non ho intenzione di perdere altro tempo, però ora sono stanco. Grazie per il costante aiuto 🙂  
P.S.: non avevo visto bene i comandi che avevi scritto quindi li avevo interpretati come risultati e ho scritto solo “irb”

---

<div class="post-metadata">

**Author:** ![RenziShish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/71e660/32.png) [@RenziShish](https://www.ruby-forum.com/u/RenziShish)\
**Post date:** [July 2, 2019, 11:39pm UTC](https://www.ruby-forum.com/t/ho-un-problema-sono-uno-nuovo-al-linguaggio-che-lo-sta-imparando/252492/16 "2019-07-02T23:39:10Z")

</div>

C’è un problema. Non rivedrò il mio computer fino a settembre, perché mia madre mi ha messo in punizione, quindi non posso fare nulla.  
☹
