Beginner's questions

Hello everyone.
I've recently picked up programming languages yet again, and since I've
spent some time on Ruby in the past already, I've decided to start from
here. However, I've encountered some problems. I've gone through
at least three tutorials already, but they are kind of useless at this
stage for me because they all focus on teaching the syntax and how to
code, while I'm stuck mostly on the tools and libraries. So, here are
my questions; feel free to redirect me towards a proper tutorial if you
wish (as long as the tutorial actually has the information I need...).

First question. How do I compile Ruby code on Linux? I've tried to look
for a compiler on Ubuntu softwere center and... failed. I'm used to
compiling C code with the gcc command from terminal, is there a similar
command for ruby code? If that's the case, what command is it and what's
the syntax? Does it have meaningful options? (Well, there's --help for
that, but I'd like to hear it first person since sometimes I've troubles
understanding the output of the terminal)

Second question. How do I work with a graphic interface? Is there a
library? If there is a library, is there a reference manual for the
library? I don't require big things, but I've never been able to
actually produce a graphical output, and tutorials do not help in any
meaningful way. I've learned to create even quite complex programs in C,
but they were always on the terminal and the most interesting graphical
output command I had was printf. Since I'm trying to write a program for
some elementary kids, I'd rather avoid the terminal altogether.

Third question. If I compile a ruby program, how can I make sure that
double clicking on it will make it run properly (and activate the above
mentioned user interface)? Again, I'm used to executing programs from
the terminal but I'd rather have something much much simpler for this
project. Do you have any advice?

I understand these are some pretty stupid questions, but they got me
stuck for quite a while and I have noone to ask them to. :slight_smile:

···

--
Posted via http://www.ruby-forum.com/.

Hi!

Please find my replies inline.

Hello everyone.
I've recently picked up programming languages yet again, and since I've
spent some time on Ruby in the past already, I've decided to start from
here. However, I've encountered some problems. I've gone through
at least three tutorials already, but they are kind of useless at this
stage for me because they all focus on teaching the syntax and how to
code, while I'm stuck mostly on the tools and libraries. So, here are
my questions; feel free to redirect me towards a proper tutorial if you
wish (as long as the tutorial actually has the information I need...).

First question. How do I compile Ruby code on Linux? I've tried to look
for a compiler on Ubuntu softwere center and... failed. I'm used to
compiling C code with the gcc command from terminal, is there a similar
command for ruby code? If that's the case, what command is it and what's
the syntax? Does it have meaningful options? (Well, there's --help for
that, but I'd like to hear it first person since sometimes I've troubles
understanding the output of the terminal)

Ruby is an interpreted programming language. so no need for compilation. All you need is the ruby interpreter.

Second question. How do I work with a graphic interface? Is there a
library? If there is a library, is there a reference manual for the
library? I don't require big things, but I've never been able to
actually produce a graphical output, and tutorials do not help in any
meaningful way. I've learned to create even quite complex programs in C,
but they were always on the terminal and the most interesting graphical
output command I had was printf. Since I'm trying to write a program for
some elementary kids, I'd rather avoid the terminal altogether.

There are bindings for gtk or qt, and also there are couple of gems which makes life easy to create GUI applications eg: shoes etc.

Third question. If I compile a ruby program, how can I make sure that
double clicking on it will make it run properly (and activate the above
mentioned user interface)? Again, I'm used to executing programs from
the terminal but I'd rather have something much much simpler for this
project. Do you have any advice?

Make the file executable.

···

On 05/12/2012 09:04 PM, Manfredi Pivetta wrote:

I understand these are some pretty stupid questions, but they got me
stuck for quite a while and I have noone to ask them to. :slight_smile:

--
Regards,
Arun.

Hello everyone.
I've recently picked up programming languages yet again, and since I've
spent some time on Ruby in the past already, I've decided to start from
here. However, I've encountered some problems. I've gone through
at least three tutorials already, but they are kind of useless at this
stage for me because they all focus on teaching the syntax and how to
code, while I'm stuck mostly on the tools and libraries. So, here are
my questions; feel free to redirect me towards a proper tutorial if you
wish (as long as the tutorial actually has the information I need...).

First question. How do I compile Ruby code on Linux?

You don't. Ruby is an interpreted language (like shell script, for example) so
you don't need to compile a program to use it. From a terminal you just write:

ruby myscript.rb

and it'll run. You can also add the line

#!/usr/bin/ruby

at the beginning of the script, make it executable (using chmod) and run it as

./myscript.rb

Second question. How do I work with a graphic interface? Is there a
library? If there is a library, is there a reference manual for the
library? I don't require big things, but I've never been able to
actually produce a graphical output, and tutorials do not help in any
meaningful way. I've learned to create even quite complex programs in C,
but they were always on the terminal and the most interesting graphical
output command I had was printf. Since I'm trying to write a program for
some elementary kids, I'd rather avoid the terminal altogether.

Ruby comes with bindings to the Tk library. You can find some documentation
at [1]. There are also bindings for other graphics libraries, such as Qt [2],
Gtk [3] and WxWidgets [4]. You can most likely find packages for them using
your distribution's package manager.

Third question. If I compile a ruby program, how can I make sure that
double clicking on it will make it run properly (and activate the above
mentioned user interface)? Again, I'm used to executing programs from
the terminal but I'd rather have something much much simpler for this
project. Do you have any advice?

That depends on the desktop environment you use.

I understand these are some pretty stupid questions, but they got me
stuck for quite a while and I have noone to ask them to. :slight_smile:

[1] TkDocs Tutorial
[2] http://techbase.kde.org/Development/Languages/Ruby
[3] http://ruby-gnome2.sourceforge.jp/
[4] http://wxruby.rubyforge.org/wiki/wiki.pl

···

Il giorno Sun, 13 May 2012 00:34:13 +0900 Manfredi Pivetta <lists@ruby-forum.com> ha scritto:

@Stefano: grazie.
The line you gave me (#!/usr/bin/ruby)... what does it exactly do? Where
can I find information on it or similar commands? The chmod you
mentioned is a library? Do I need to import libraries manually like in
C? The environment I used in the past had a bunch of pre-written hidden
code that might have done it, so I'm a bit confused at the moment.

I'll look into the packages you've linked. As for the third question,
the program will need to work on Windows.

···

--
Posted via http://www.ruby-forum.com/.

First question. How do I compile Ruby code on Linux? I've tried to
look for a compiler on Ubuntu softwere center and... failed. I'm used
to compiling C code with the gcc command from terminal, is there
a similar command for ruby code?

Be warned that debian is a stupid distribution that believes that the
user is an idiot. It shows so by splitting up packages into 10000
different subpackages, crippling them all by default. Yes - splitting
away the header files BY DEFAULT, without giving the user a GLOBAL way
to REVERT this idiotic decision, is crippling packages.

Even worse, they dump every shit into /usr prefix rather than package
things up neatly into AppDirs.

Anyway. I write this because you must be warned. If you really want
to compile Ruby code on "linux", but then write you are on ubuntu,
you may already have a crippled ruby version in /usr prefix.

If you want to use your own compiled ruby, remove all the ubuntu ruby
shit. This is usually /usr/bin/ruby ruby1.8 ... then in /usr/lib some
ruby. Also check for irb and ri (but I think by default they dont
provide ri, as stupid as debian is.)

Once you removed the crippled ruby, you must decide which ruby
version you want to compile:

  ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.bz2
  ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p358.tar.bz2

I myself still use 1.8.7 because of the useless Encoding addition
to 1.9.3, which I never need, and never will need. But be aware
that ruby 1.8.7 is more or less dead, so you need to keep in mind
the option to upgrade one day. If you pick 1.9.3, that of course
does not apply to you.

Download this. Then extract it and enter the directory.

Now, you need to decide on a proper prefix to configure.

I recommend /usr prefix.

./configure --prefix=/usr

I personally however use:

./configure --prefix=/Programs/Ruby/1.8.7p358

After configure phase, do make and then make install in the
traditional way. There is an optional step to install the
documentation, but you can skip it for now. The first part
is just to ensure that you can actually COMPILE ruby.

On my system I can, but on a default crippled ubuntu system
some header files may be missing. You have to uncripple this,
i.e. by apt-get install build-essentials. Or some other
command, I really dont know and dont want to know either (I
compile all that ruby requires on my own anyway, from source).

If everything worked well, ruby is now installed into /usr
prefix. (I use symlinks for the /Programs/Ruby/1.8.7p358
approach, so this may be hard for you. RVM uses a similar
approach by the way.)

If that's the case, what command is it and what's
the syntax?

If you decide on /usr prefix, configure + prefix, make,
make install are sufficient. You can also use prefix
/usr/local (which is the default for configure, if
--prefix=/usr was omitted) or /opt - personally I find
these all ugly compared to app-dirs, but sadly the Linux
world is too stupid to move away from /usr scheme, and
they will use a lot of propaganda to justify the DEFAULT
way - I always laugh when I hear that, because they
justify being LAZY and UNABLE to use ANYTHING else. (Yup,
sadly Gobolinux is dead ... NixOS has cool ideas, but the
idea to store the hash as part of the DIRECTORY name is
NOT user friendly at all.)

Does it have meaningful options?

There are some options. For instance, I often tend to use:

--enable-pthread
--enable-install-doc
--with-static-linked-ext

The last may be a problem. Anyway, the options should not
be important at all. Just try to make it WORK first. :slight_smile:

(Well, there's --help for that, but I'd like to hear
it first person since sometimes I've troubles
understanding the output of the terminal)

Understandable. I still have not managed to compile a
static ruby, unfortunately. I'd really love a static
ruby, because I tend to break things on my system a
lot, and then I have to fix it up again. (I recently
broke my bash shell, by removing ncurses. Sadly,
/bin/sh depended on shared ncurses library, and thus
my system was no longer working. Since then, I always
compile bash statically - I dont understand why such
BASIC things are compiled in a shared way. This just
leads to a more fragile system IMO.)

Second question. How do I work with a graphic interface?
Is there a library?

Ruby gtk works well on Linux and Windows. Unfortunatly
GUI in Ruby are a WEAK point ...

If there is a library, is there a reference manual for
the library?

Yes, for ruby-gtk. Download the official source. It has
about 300 examples or some such. I never managed to read
them all. :slight_smile:

I don't require big things, but I've never been able
to actually produce a graphical output

Ruby-Qt and Ruby-Tk also work. Ruby-Qt would be the best,
but it has no real documentation and almost no users
that I can see.... which is sad. Qt is better than GTK,
but I prefer to use GTK for ruby simply because it works
so much better and there are more people that use it than
QT.

and tutorials do not help in any meaningful way.

Then simply look at the examples and run them. Then
tweak them.

That is how I learned Ruby-Gtk (+ I kept my local docu)

I've learned to create even quite complex programs in C,
but they were always on the terminal and the most
interesting graphical output command I had was
printf.

Same way with Ruby too. But 30% of the code only. Perhaps
even less so, if you write your own libraries and classes
that simplify this even further. :wink:

Since I'm trying to write a program for some elementary
kids, I'd rather avoid the terminal altogether.

The terminal OUTPUT, but you can build your PROGRAM in a
MODULAR way. Then you can decide what you want to use at
any time. I always start with terminal output design, and
design it in a way that I can hook up a GUI to it at a
later time (but as said, sadly, the GUIs in Ruby are not
that great).

Third question. If I compile a ruby program, how can I make sure
that double clicking on it will make it run properly (and activate
the above mentioned user interface)?

You do not COMPILE a ruby program. :frowning:

Did you even read up on Ruby on wikipedia at all?

Anyway, if you want to provide your program to others, you
should create a gem for your project.

If the name is foobar of your project, then they can install it
like so:

  gem install foobar

I understand these are some pretty stupid questions, but they
got me stuck for quite a while and I have noone to ask them to. :slight_smile:

They are not stupid, they only show that you do not have sufficient
knowledge to answer them for your own at this point.

I recommend you to start with a TERMINAL program in Ruby, because
it is SIMPLER. Keep it small, simple, and have it solve one or a
few tasks very well. THEN, declare it finished, and turn it into
a gem. Then upload this.

Once you did this, you can THEN try to use a GUI.

···

--
Posted via http://www.ruby-forum.com/\.

@Stefano: grazie.
The line you gave me (#!/usr/bin/ruby)... what does it exactly do? Where
can I find information on it or similar commands?

In Unix systems (including linux) that line, at the beginnning of a script,
tells the operating system which progrogram to use to execute it. See [1] for
more.

The chmod you mentioned is a library?

chmod is a standard command line program on all Unix systems (including
linux). It is used to change the permissions on a file or directory. To know
more about it you can look at its man page with the command

man chmod

You can also look at the wikipedia entry on it ([2]).

Do I need to import libraries manually like in
C? The environment I used in the past had a bunch of pre-written hidden
code that might have done it, so I'm a bit confused at the moment.

If I understand your question correctly, yes you do. To use a library, you
must first install it, which often is done with a simple

gem install libraryname

issued from a terminal (you should consult the library documentation,
however). After that, from your ruby program, you require the library with:

require 'libraryfile'

Often, libraryfile is the same as the name of the library. Again, for more
information, you should look at the documentation for the library. Also, look
at any ruby tutorial for more documentation about require.

I'll look into the packages you've linked. As for the third question,
the program will need to work on Windows.

I fear I can't help you there, as I've never tried to do this on windows.

Stefano

[1] Shebang (Unix) - Wikipedia
[2] chmod - Wikipedia

···

Il giorno Sun, 13 May 2012 01:17:26 +0900 Manfredi Pivetta <lists@ruby-forum.com> ha scritto: