What is Ruby?

Lately there have been a lot of one-liners posted in "ruby" on the apparent assumption that mainstream unix or Linux come with "ruby. They don't.

  1. What is "ruby"?
  2. What platforms and Operating System versions are supported?
  3. The syntax for "ruby" seems remarkably obscure compared with say "awk" or "perl". Is it related to APL?

Reference:

Ruby (programming language) - Wikipedia, the free encyclopedia

1 Like

Just another programming language

the usual, Solaris, Windows,Linux, MacOS. etc

that's because you don't know about it. Same concept as a person who doesn't understand Perl/awk will find them "obscure" as well.

who says one has to solve everything using just "mainstream" tools? And how do you define mainstream? For example, nowadays, linux packages/CDs comes with Ruby. Either its selected by default or an administrator can choose to install it. Now, does the system become "mainstream" in that situation, or not?
Ruby is just a tool like any other languages out there, Perl, Python you name it.

3 Likes

I agree. It is pretty easy to install, for example on Debian / Ubuntu:

root@myserver:/home/neo/bin# ruby
The program 'ruby' is currently not installed.  You can install it by typing:
apt-get install ruby
ruby: command not found

On my Mac, is it installed "out of the box".

OSX: man ruby

See also: Apropos for Ruby

See also: Ruby Home Page (English)

1 Like

Thanks for the links.

Having now seen properly laid out whole programs in Ruby the language structure is a bit clearer. I still am surprised that a modern programming language can have an obscure syntax.

Having first learnt to program in Algol 68, I find Python easiest to follow of the modern crop of languages. I've used a large number of programming and scripting languages over the years and have my favourites.

Understood.

I don't program in Ruby, but a lot of people do!

Seem interesting, from a OO scripting perspective.

Having now read the roots of "Ruby" are in "Lisp" it's giving me flashbacks. I found "Lisp" a pain the first time around compared with some of the contemporary languages.

Thank you all again for your responses. I've been bursting to ask the question for weeks.

almost everything in Ruby is object based. For example, in Perl, you write for loop like this

for ($i=0; $i<10; $i++) {
  ....
}

in Ruby,

1.upto(10).each{|x| puts x}  # 1 is an integer class with method upto()

or

(1..10).each{|x| puts x}  # (1..10) provides a range...like in Perl

There is no using loops here. "Looping" is taken care of by the programming language itself (of course, there are also for loops in Ruby :slight_smile: ). If you are accustomed to procedural programming where you use for loops often, this might seem "obscure" at first.

1 Like

So Ruby is a "declarative" programming language v. a "procedural" one?

Do you mean functional programming ? ( Its a more familiar term to me. ). If you do indeed mean functional programming, then yes, Ruby supports that. In fact, in the wiki page you provided, its stated it support multi paradigms. :slight_smile:

Ruby can be used as "procedural" as well.... with that i mean, in the script, there isn't a single user defined class. :slight_smile:

No, I actually meant "declarative" .... See this reference:

---------- Post updated at 12:48 ---------- Previous update was at 12:45 ----------

Follow-up:

I see now that Ruby is not classified as a "declarative programming language", List of programming languages by category.

I see. Well, I am not sure about the distinctions between them...but i want to assume that if Ruby support functional prog , regular expression, then i would expect it to be a bit "declarative" as well. :slight_smile:

Ruby is not a declarative language (think SQL and XSL) per se.

Hi.

I'm glad that methyl brought this up.

I've been leisurely following ruby for a few years. I have one production code, glark, written in ruby. It is a grep-like utility, with lots of bells and whistles -- very slow, but very convenient in some situations. You might find it in one of your repositories, or at:
incava.org

However, whenever I have tried to execute kurumi's one-liners, say:

ruby -ne 'BEGIN{s = 0};s+=$_.to_f;END{print "Total: #{s}\n"}' file

I get:

-e:1: undefined method `+' for nil:NilClass (NoMethodError)

This is from:

ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]

but I also got it on new install of ruby-full on:

OS, ker|rel, machine: Linux, 2.6.32-24-generic, i686
Distribution        : Ubuntu 10.04.1 LTS (lucid) 
ruby 1.8.7 (2010-01-10 patchlevel 249) [i486-linux]

Something simple, perhaps, that I am over-looking? ... cheers, drl