
-----------------------------------
HyperFlexed
Sun Nov 21, 2004 2:37 am

Ruby... from Turing
-----------------------------------
I decided to learn another language...

I downloaded freeRide, but now I have no idea what to do. I've tried writing a few programs, but when I run them, the program crashes.

I have a few questions.

how do I declare a variable?
how do I initialize a variable?
how do I display something?
how would this be written in Ruby? (put "A string mixed with ", aNumVar)

Also, could someone show me the HelloWorld program in Ruby? I tried finding my own tuts, but damn. There is all this amazingly intimidating jargon all over the pages, and I don't know wtf is going on.

-----------------------------------
Tony
Sun Nov 21, 2004 4:22 am


-----------------------------------

text = "hello world"
puts text


num = 3.1415
puts "pi is #{num}"
 :)

-----------------------------------
HyperFlexed
Sun Nov 21, 2004 12:56 pm


-----------------------------------
wow... interesting. No formal varaible declarations.

I have another question, are programming blocks in any way like procedures and functions? It would make sense because any variable "declared" in them are not global.

thx alot btw.. I think when I get the hang of Ruby I'm going to write a big tutorial from an idiots POV.

-----------------------------------
HyperFlexed
Sun Nov 21, 2004 12:57 pm


-----------------------------------
P.S, anyone know any good IDE's for Ruby? I'm not really liking FreeRIDE at all. Should it just run my programs? or do I have to install some kind of Ruby thingamajigger?

-----------------------------------
wtd
Sun Nov 21, 2004 2:15 pm


-----------------------------------
P.S, anyone know any good IDE's for Ruby? I'm not really liking FreeRIDE at all. Should it just run my programs? or do I have to install some kind of Ruby thingamajigger?

For learning the basics, use IRB.  Start -> Run, then type "irb" and hit enter.

-----------------------------------
HyperFlexed
Sun Nov 21, 2004 2:18 pm


-----------------------------------
P.S, anyone know any good IDE's for Ruby? I'm not really liking FreeRIDE at all. Should it just run my programs? or do I have to install some kind of Ruby thingamajigger?

For learning the basics, use IRB.  Start -> Run, then type "irb" and hit enter.

ummmm... I think I need to install something first because that didn't work.

-----------------------------------
wtd
Sun Nov 21, 2004 2:28 pm


-----------------------------------
wow... interesting. No formal varaible declarations.

No, you don't have to declare variables.  It can be a real time-saver.

I have another question, are programming blocks in any way like procedures and functions? It would make sense because any variable "declared" in them are not global.

Somewhat.  There are a few ways of creating a block.  We can either explicitly create a new Proc object:

add = Proc.new { |a, b| a + b }

We can use the lamnda method, which often jives better with math people:

add = lambda { |a, b| a + b }

And now, if we have a function which takes a block as an argument...

The & indicates the argument is a block

def two_and_two(&block)
   block.call(2, 4)
end

We can either call it using the existing block:

two_and_two(add)

Or we can pass it a new block:

two_and_two { |a, b| a + b }

The other way to use a block with a function is to "yield" the variables out to any block that might be included.

def two_and_two
   yield 2, 2
end

And we can call it in the same way:

two_and_two { |a, b| a + b }

The power of this, vs. other methods in other languages is... what if I want to multiply two and two?

two_and_two { |a, b| a * b }

-----------------------------------
wtd
Sun Nov 21, 2004 2:30 pm


-----------------------------------
P.S, anyone know any good IDE's for Ruby? I'm not really liking FreeRIDE at all. Should it just run my programs? or do I have to install some kind of Ruby thingamajigger?

For learning the basics, use IRB.  Start -> Run, then type "irb" and hit enter.

ummmm... I think I need to install something first because that didn't work.

http://rubyinstaller.rubyforge.org/wiki/wiki.pl

-----------------------------------
HyperFlexed
Sun Nov 21, 2004 6:01 pm


-----------------------------------
all those code examples, are all of those things keywords or something?

ruby is very minimalist. I think it's retarted.

-----------------------------------
Tony
Sun Nov 21, 2004 6:25 pm


-----------------------------------
I think you should take a break... *click click* We'll see you tomorrow :)

-----------------------------------
wtd
Sun Nov 21, 2004 7:41 pm


-----------------------------------
all those code examples, are all of those things keywords or something?

Only "def", "end", ".", and the basic "{ | |  }" construct are part of the syntax.

"Proc" is a class, "new" is a method of that class, "two_and_two" is a user-defined method, and "lambda" is a method of the Object class.

-----------------------------------
Andy
Sun Nov 21, 2004 8:00 pm


-----------------------------------
ruby is very minimalist. I think it's retarted.

the point of ruby was to be simple, so its not a pain to program

-----------------------------------
wtd
Sun Nov 21, 2004 8:17 pm


-----------------------------------
ruby is very minimalist. I think it's retarted.

the point of ruby was to be simple

And don't forget flexible.  :)
