What is Ruby?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting What is Ruby?
# 8  
Old 09-21-2010
Quote:
Originally Posted by methyl
I still am surprised that a modern programming language can have an obscure syntax.
almost everything in Ruby is object based. For example, in Perl, you write for loop like this
Code:
for ($i=0; $i<10; $i++) {
  ....
}

in Ruby,
Code:
1.upto(10).each{|x| puts x}  # 1 is an integer class with method upto()

or
Code:
(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 Smilie ). If you are accustomed to procedural programming where you use for loops often, this might seem "obscure" at first.
This User Gave Thanks to kurumi For This Post:
# 9  
Old 09-21-2010
So Ruby is a "declarative" programming language v. a "procedural" one?
# 10  
Old 09-21-2010
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. Smilie

Ruby can be used as "procedural" as well.... with that i mean, in the script, there isn't a single user defined class. Smilie
# 11  
Old 09-21-2010
No, I actually meant "declarative" .... See this reference:
Quote:
In computer science, declarative programming is a programming paradigm that expresses the logic of a computation without describing its control flow. Many languages applying this style attempt to minimize or eliminate side effects by describing what the program should accomplish, rather than describing how to go about accomplishing it. This is in contrast with imperative programming, which requires an explicitly provided algorithm.

Declarative programming often considers programs as theories of a formal logic, and computations as deductions in that logic space. Declarative programming has become of particular interest recently, as it may greatly simplify writing parallel programs.

Common declarative languages include those of regular expressions, logic programming, and functional programming.


---------- 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.
# 12  
Old 09-21-2010
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. Smilie
# 13  
Old 09-21-2010
Ruby is not a declarative language (think SQL and XSL) per se.
# 14  
Old 09-21-2010
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:
Code:
ruby -ne 'BEGIN{s = 0};s+=$_.to_f;END{print "Total: #{s}\n"}' file

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

This is from:
Code:
ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]

but I also got it on new install of ruby-full on:
Code:
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
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. What is on Your Mind?

Ruby language

Hi All, Could you please suggest books for learning ruby and python language ? Thanks, Pravin (1 Reply)
Discussion started by: pravin27
1 Replies

2. Shell Programming and Scripting

Printf with backreference in ruby

Hello everybody, May you help with this, I don't know what is wrong. I want trying to print the first 4 characters as decimal and remove the "k's" from the next 7 characters. I'm trying with gsub and backrefence as shown below trying to remove the "k's" and then trying to assign to "x" the... (0 Replies)
Discussion started by: Ophiuchus
0 Replies

3. UNIX for Advanced & Expert Users

Need help installing Puppet and Ruby..

Hi, I am working on RHEL 5.6 server, this is in private DMZ. No access to internet. I have downloaded the files I need to install the Puppet & Ruby. My goal is to install Puppet. I have downloaded.... mcollective-2.2.3-1.el5.noarch- SERVER.rpm ... (2 Replies)
Discussion started by: samnyc
2 Replies

4. Programming

Ubuntu ruby on rails

Hi, I am a php developer and I decided to learn ruby on rails. I have a few question. I have an ubuntu virtual machine with lamp. It mean that it has alrweady php and when I access the ip of the machine from my browser it does load the index.php. if I install ruby on rails will theere... (0 Replies)
Discussion started by: programAngel
0 Replies

5. Shell Programming and Scripting

Parsing the Ruby File

Hai any one pls guide me... We can extract the line number of the sub routine/function/method in a Ruby file using the ctags command. But I want to know the line number in which the sub routine is ending. Example: Say the function get_days_in_hash starts in the line number 20. It... (2 Replies)
Discussion started by: thillai_selvan
2 Replies

6. SuSE

how to ri-rdoc for Ruby on suse

Hello guys, This is suse SLES 9.2. I want to get ri working for all users on this system. I used gem rdoc --all --ri to generate documentation and it went on doing it successfully. Then I tried ri Array It shows following message : Nothing known about Array Therefore I ran... (0 Replies)
Discussion started by: upengan78
0 Replies
Login or Register to Ask a Question