From: Emma Pidre on
Hi, i am in Osx and i had installed Ruby 1.8.7. I want to make a
tutorial, i am a beginner in ruby. My problem is that when i want to
execute a program on ruby, example: code.rb, with "ruby code.rb" on
Terminal, like all tutorials sais, a error come back: "-bash: code.rb:
command not found"

Well, there is a part that i am missing. Please help me.
--
Posted via http://www.ruby-forum.com/.

From: Francesco Vollero on
Il 29/05/10 21.43, Emma Pidre ha scritto:
> Hi, i am in Osx and i had installed Ruby 1.8.7. I want to make a
> tutorial, i am a beginner in ruby. My problem is that when i want to
> execute a program on ruby, example: code.rb, with "ruby code.rb" on
> Terminal, like all tutorials sais, a error come back: "-bash: code.rb:
> command not found"
>
> Well, there is a part that i am missing. Please help me.
>
It's ok, you want to run it as a normal command if i understand well.
First thing to do, is adding a "shebang"[1] at top of your ruby file.
After that, you have to make it executable, and, to do it you have to
write on bash command line, chmod +x code.rb and voilĂ , your ruby script
as executable in this way: ./code.rb

Have fun with ruby,
-Francesco



[1] shebang: "/usr/bin/env ruby"

From: Josh Cheek on
[Note: parts of this message were removed to make it a legal post.]

On Sat, May 29, 2010 at 2:43 PM, Emma Pidre <equisigriegazeta(a)gmail.com>wrote:

> Hi, i am in Osx and i had installed Ruby 1.8.7. I want to make a
> tutorial, i am a beginner in ruby. My problem is that when i want to
> execute a program on ruby, example: code.rb, with "ruby code.rb" on
> Terminal, like all tutorials sais, a error come back: "-bash: code.rb:
> command not found"
>
> Well, there is a part that i am missing. Please help me.
> --
> Posted via http://www.ruby-forum.com/.
>
>
Expounding on Francesco's answer:

# add a shebang to the top of a file called hello_world.rb
# this directs the system(?) to use Ruby to interpret the file
$ echo '#!/usr/bin/env ruby' > hello_world.rb

# append a statement that will output "hello world" to hello_world.rb
$ echo 'puts "hello world"' >> hello_world.rb

# set permissions of hello_world.rb so that you can execute it
$ chmod 755 hello_world.rb

# execute hello_world.rb and see that it outputs "hello world"
# the ./ in front is important, it says the file is located in the current
directory
$ ./hello_world.rb
hello world

From: Francesco Vollero on
Il 30/05/10 13.20, Josh Cheek ha scritto:
> On Sat, May 29, 2010 at 2:43 PM, Emma Pidre<equisigriegazeta(a)gmail.com>wrote:
>
>
>> Hi, i am in Osx and i had installed Ruby 1.8.7. I want to make a
>> tutorial, i am a beginner in ruby. My problem is that when i want to
>> execute a program on ruby, example: code.rb, with "ruby code.rb" on
>> Terminal, like all tutorials sais, a error come back: "-bash: code.rb:
>> command not found"
>>
>> Well, there is a part that i am missing. Please help me.
>> --
>> Posted via http://www.ruby-forum.com/.
>>
>>
>>
> Expounding on Francesco's answer:
>
> # add a shebang to the top of a file called hello_world.rb
> # this directs the system(?) to use Ruby to interpret the file
> $ echo '#!/usr/bin/env ruby'> hello_world.rb
>
> # append a statement that will output "hello world" to hello_world.rb
> $ echo 'puts "hello world"'>> hello_world.rb
>
> # set permissions of hello_world.rb so that you can execute it
> $ chmod 755 hello_world.rb
>
> # execute hello_world.rb and see that it outputs "hello world"
> # the ./ in front is important, it says the file is located in the current
> directory
> $ ./hello_world.rb
> hello world
>
>
You're right, maybe my answer can get someone confused, to be 100% sure,
Josh, let me write a ruby script :)

ruby_sample.rb:
--
#!/usr/bin/env ruby

puts "hello world"
--

and after you've to do what Josh say i mean, 3rd and 4th step.

-Francesco


From: Emma Pidre on
Hi, trhans for the answer. This is not working. I saw that already had
the first line of code in the example i trying to run : "#!/usr/bin/env
ruby".

The error is the same:
"ruby: No such file or directory -- ./code.rb (LoadError)"

The person who sold me the Macbook, said to me that he made some
troubles with ruby. I don't know what is wrong, maybe is a configuration
troubles or something like that. i can use directly from textMate, but i
want to resolve the problem form Terminal, to be more sure that all work
fine.

there is a way for restart ruby, i mean, unistall o delete all files or
something like that for make a re-install later ? What did you advise
me?

Thanks for all ! :) im very happy to find i place where find help.
--
Posted via http://www.ruby-forum.com/.