Learning Ruby


#1

Okay I’ve went through Chris P.s tutorial on
programming(http://pine.fm/LearnToProgram/), and I still don’t fully
understand what I hear from experienced Ruby programmers. Is there any
other tutorials that you might spare for a newbly soul such as mine?


#2

Try “programming ruby”. The first edition of it can be accessed for
free,
although I recommend that you buy the second edition of it.

2006/4/19, Jesse M removed_email_address@domain.invalid:


#3

Jesse M wrote:

Okay I’ve went through Chris P.s tutorial on
programming(http://pine.fm/LearnToProgram/), and I still don’t fully
understand what I hear from experienced Ruby programmers. Is there any
other tutorials that you might spare for a newbly soul such as mine?

What don’t you understand?

Cheers,
Dave


#4

Jesse M wrote:

Okay I’ve went through Chris P.s tutorial on
programming(http://pine.fm/LearnToProgram/), and I still don’t fully
understand what I hear from experienced Ruby programmers. Is there any
other tutorials that you might spare for a newbly soul such as mine?

http://ruby-doc.org/gettingstarted

http://ruby-doc.org/whyruby


James B.

?Design depends largely on constraints.?
? Charles Eames


#5

It can be hard to notice the nice little things until you actually
implement something. I’m just now knee deep in my first Ruby-based
project, and not until just recently have I seen what people are talking
about.

Basically, it’s all just time-saving stuff that doesn’t make ugly code.
You wont appreciate it until you write some code that should be hideous,
but turns out (almost) elegant.

Now that I’ve posted this, I’m off to post about something weird,
unpredictable and frustrating that I’ve found in Ruby :slight_smile:


#6

Jesse M wrote:

Okay I’ve went through Chris P.s tutorial on
programming(http://pine.fm/LearnToProgram/), and I still don’t fully
understand what I hear from experienced Ruby programmers. Is there any
other tutorials that you might spare for a newbly soul such as mine?

http://ruby-doc.org/gettingstarted

http://ruby-doc.org/whyruby


James B.

?Design depends largely on constraints.?
? Charles Eames


#7

I don’t know the syntax.But I think it is same as

[1,2,3].all? {|i| i.positive?}

On 4/20/06, Jesse M removed_email_address@domain.invalid wrote:

Cheers,
[1, 2, 3].all? &:positive? => true
[-1, 2, 3].all? &:positive? => false

which i don’t understand half of it :slight_smile: and i’m really gung hoe about it!


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


Chaoqun Li
ThoughtWorks(Xi’an)
mobile phone:13909217679
office phone:029-87607341


#8

Dave B. wrote:

Jesse M wrote:

Okay I’ve went through Chris P.s tutorial on
programming(http://pine.fm/LearnToProgram/), and I still don’t fully
understand what I hear from experienced Ruby programmers. Is there any
other tutorials that you might spare for a newbly soul such as mine?

What don’t you understand?

Cheers,
Dave

Well I see something like,

lass Numeric
def positive?
self > 0
end
end

[1, 2, 3].all? &:positive? => true
[-1, 2, 3].all? &:positive? => false

which i don’t understand half of it :slight_smile: and i’m really gung hoe about it!


#9

:positive? is a symbol, so it can’t be converted into a block:

yes it can, using the extensions gem and require ‘extensions/symbol’
http://extensions.rubyforge.org/rdoc/classes/Symbol.html
(or by defining your own Symbol#to_proc method)


#10

Jesse M wrote:

Well I see something like,

lass Numeric
def positive?
self > 0
end
end

I assume you understand this from Pine’s LtP.

[1, 2, 3].all? &:positive? => true
[-1, 2, 3].all? &:positive? => false

which i don’t understand half of it :slight_smile: and i’m really gung hoe about it!

Have you tried typing this into IRB? I think you’ll find it doesn’t even
work.

The & symbol is used to get a Proc from a block passed into a method

class Array
def eachEven(&wasABlock_nowAProc) # from LtP Online Chapter 10

or to convert a Proc into a block when calling a method

f = proc do |oddBall|
puts oddBall.to_s+’ is NOT an even number!’
end
[1, 2, 3, 4, 5].eachEven &f

:positive? is a symbol, so it can’t be converted into a block:

all? and positive? are just methods (methods can end in !, =, or ?).

irb(main):001:0> [1,2,3].all? &:positive?
TypeError: wrong argument type Symbol (expected Proc)
from (irb):1

Then, the “=> true” and “=> false” aren’t actually Ruby code, they’re
just meant to show the reader the value of that expression. Usually we
put a # in front so it’s valid Ruby code:

positive = proc {|n| n > 0 }
[1, 2, 3].all? &positive #=> true
[-1, 2, 3].all? &positive #=> false

Do you follow that (working) rewrite of the snippet? If you type it into
IRB, you should see the results listed after the “#=>”.

Anyway, for further reading, I recommend Why’s (Poignant) Guide to Ruby
if you can deal with reading a wacky story in between learning more
Ruby.

http://www.poignantguide.net/ruby/

Or there’s the standard reference, the Pickaxe.

Or you can just ask the list when you have a question!

All the best!
Dave