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.
(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.
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.
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.
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.
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/\.