[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

greetings

Mage

1/23/2006 3:57:00 PM

Hello,

some months ago I started to use Python and to see the light.

Now my eyes are a bit burned so I went back to the darkness (for some
glittering red gem). I started Ruby.

I read almost the whole pragmatic programmer book without writing a
piece of code, except this: 15.times { puts 'I love you, xxx'}, where
xxx were my girlfriend's name. From that moment she also started to like
Ruby.

It is a good book. However, it is based on Ruby 1.6. I failed to find
something like "what changed from 1.6 to 1.8". Can you help me?

Also, the reference is hard to read. It took a simple google session to
find the quoted-printable method (Array.pack('M')). I think it could be
easier to find in the manual.

Setting up postgresql was quite easy (apt-get install libpgsql-ruby).
The documented PGconn.open method generated error, it said that it is
protected method. I use PGconn.new. Is it normal? I cannot skip the
'port' parameter with the new method.

On the whole I am happy with my first Ruby script and with the language
itself.

Mage






12 Answers

Joe Van Dyk

1/23/2006 4:13:00 PM

0

On 1/23/06, Mage <mage@mage.hu> wrote:
> Hello,
>
> some months ago I started to use Python and to see the light.
>
> Now my eyes are a bit burned so I went back to the darkness (for some
> glittering red gem). I started Ruby.
>
> I read almost the whole pragmatic programmer book without writing a
> piece of code, except this: 15.times { puts 'I love you, xxx'}, where
> xxx were my girlfriend's name. From that moment she also started to like
> Ruby.
>
> It is a good book. However, it is based on Ruby 1.6. I failed to find
> something like "what changed from 1.6 to 1.8". Can you help me?

The second edition of the book was released two years ago or so and
covers Ruby 1.8. You should read that one instead.

Here's a pretty good summary of the changes in Ruby 1.8.
http://whytheluckystiff.net/articles/rubyOneEi...


James Gray

1/23/2006 6:07:00 PM

0

On Jan 23, 2006, at 9:56 AM, Mage wrote:

> Hello,

Hello and welcome to Ruby.

> I read almost the whole pragmatic programmer book without writing a
> piece of code, except this: 15.times { puts 'I love you, xxx'},
> where xxx were my girlfriend's name. From that moment she also
> started to like Ruby.
>
> It is a good book. However, it is based on Ruby 1.6.

Actually, the current version of the Pickaxe covers very modern Ruby:

http://www.pragmaticprogrammer.com/titles/ruby/...

I strongly recommend picking it up.

> I failed to find something like "what changed from 1.6 to 1.8". Can
> you help me?

The top hit from Google for "What's new in Ruby 1.8" is:

http://whytheluckystiff.net/articles/rubyOneEi...

;)

James Edward Gray II



Mage

1/23/2006 6:19:00 PM

0

Joe Van Dyk wrote:

>On 1/23/06, Mage <mage@mage.hu> wrote:
>
>
>
>The second edition of the book was released two years ago or so and
>covers Ruby 1.8. You should read that one instead.
>
>Here's a pretty good summary of the changes in Ruby 1.8.
>http://whytheluckystiff.net/articles/rubyOneEi...
>
>
Thanx.

One of the things I don't understand are the semicolons. When I read the
Book, it said:

class SomeThing
atrr_reader :x, :y
end

I figured out that the attr_reader need to get the name of the instance
variables.

However, what is this code good for?

def make_point_hash( point )
center = { :x => 1, :y => 2 }
big = { :r => 10 }
center.merge( big ).merge( point )
end
make_point_hash( { :x => 20 } )

#=> {:y=>2, :r=>10, :x=>20}

What is that those semicolons do?

Mage





Gene Tani

1/23/2006 6:28:00 PM

0


Mage wrote:

>
> However, what is this code good for?
>
> def make_point_hash( point )
> center = { :x => 1, :y => 2 }
> big = { :r => 10 }
> center.merge( big ).merge( point )
> end
> make_point_hash( { :x => 20 } )
>
> #=> {:y=>2, :r=>10, :x=>20}
>
> What is that those semicolons do?
>
> Mage

these articles on symbols were written for you:

http://glu.ttono.us/articles/2005/08/19/understanding-ru...
http://onestepback.org/index.cgi/Tech/Ruby/SymbolsAreNotImmuta...
http://www.oreillynet.com/ruby/blog/2005/12/digging_into_ruby_sy...
http://www.oreillynet.com/ruby/blog/2005/12/symbols_strings_methods_a...
http://microjet.ath.cx/WebWiki/2005.12.27_UsingSymbolsForTheWrongR...
http://www.rubycentral.com/faq/rubyfaqa...
http://moonbase.rydia.net/mental/blog/programming/ruby-symbols-expl...

Zach

1/23/2006 6:36:00 PM

0

I may be totally off base, being a Ruby Newbie myself, but I believe the
point of the :variable is sort of passing a HashMap to the method...for
instance:

inside the method
center = { :x => 1, :y => 2 }

you can refer to the parameters as :x and :y. As opposed to mandating
the prototype of the method being center(x, y).

The benefits I can see are variable length arguments, and the arguments
placed don't have to be in the same order. Coming from java, I'm
actually a little wary about this, but I sort of understand the
usefulness, especially after reading the Rails book.

-Zach


Mage wrote:

> Joe Van Dyk wrote:
>
>> On 1/23/06, Mage <mage@mage.hu> wrote:
>>
>>
>>
>> The second edition of the book was released two years ago or so and
>> covers Ruby 1.8. You should read that one instead.
>>
>> Here's a pretty good summary of the changes in Ruby 1.8.
>> http://whytheluckystiff.net/articles/rubyOneEi...
>>
>>
> Thanx.
>
> One of the things I don't understand are the semicolons. When I read
> the Book, it said:
>
> class SomeThing
> atrr_reader :x, :y
> end
>
> I figured out that the attr_reader need to get the name of the
> instance variables.
>
> However, what is this code good for?
>
> def make_point_hash( point )
> center = { :x => 1, :y => 2 }
> big = { :r => 10 }
> center.merge( big ).merge( point ) end
> make_point_hash( { :x => 20 } )
>
> #=> {:y=>2, :r=>10, :x=>20}
>
> What is that those semicolons do?
>
> Mage
>
>
>
>
>


Mark Volkmann

1/23/2006 6:53:00 PM

0

On 1/23/06, Zach <zacharooni@comcast.net> wrote:
> I may be totally off base, being a Ruby Newbie myself, but I believe the
> point of the :variable is sort of passing a HashMap to the method...for
> instance:
>
> inside the method
> center = { :x => 1, :y => 2 }

The fact that the right-hand side is surrounded by curly braces is
what makes it a Hash. Each key/value pair initially added to the Hash
looks like "key => value". In this particular case, they decided to
use symbols for keys which is pretty common. The colon means that the
word following it is a symbol. They could have also used String keys.

There was a long discussion about what symbols are recently, so I
hesitate to try to simplify this, but here goes. Think of a symbol as
a string that will be the same object in memory each time you use it.
For example, "foo" and "foo" will be two different objects in memory,
but :foo and :foo will refer to the same object.

> you can refer to the parameters as :x and :y.

Well, in a Hash they are called keys.

> As opposed to mandating
> the prototype of the method being center(x, y).

That's a good point. Passing a Hash to a method, in a way, allows you
to pass arbitrary parameters if you think of the keys as being
parameter names the values as being parameter values.

> The benefits I can see are variable length arguments, and the arguments
> placed don't have to be in the same order. Coming from java, I'm
> actually a little wary about this, but I sort of understand the
> usefulness, especially after reading the Rails book.

I don't think it's common in Ruby to use Hashes for this purpose.
Usually methods have fixed parameters and you don't pass them in a
Hash.

> Mage wrote:
>
> > Joe Van Dyk wrote:
> >
> >> On 1/23/06, Mage <mage@mage.hu> wrote:
> >>
> >>
> >>
> >> The second edition of the book was released two years ago or so and
> >> covers Ruby 1.8. You should read that one instead.
> >>
> >> Here's a pretty good summary of the changes in Ruby 1.8.
> >> http://whytheluckystiff.net/articles/rubyOneEi...
> >>
> >>
> > Thanx.
> >
> > One of the things I don't understand are the semicolons. When I read
> > the Book, it said:
> >
> > class SomeThing
> > atrr_reader :x, :y
> > end
> >
> > I figured out that the attr_reader need to get the name of the
> > instance variables.
> >
> > However, what is this code good for?
> >
> > def make_point_hash( point )
> > center = { :x => 1, :y => 2 }
> > big = { :r => 10 }
> > center.merge( big ).merge( point ) end
> > make_point_hash( { :x => 20 } )
> >
> > #=> {:y=>2, :r=>10, :x=>20}
> >
> > What is that those semicolons do?
> >
> > Mage
> >
> >
> >
> >
> >
>
>


--
R. Mark Volkmann
Partner, Object Computing, Inc.


Michael Bannister

1/23/2006 6:56:00 PM

0

I think you mean colons ( : ) not semicolons ( ; ) !

The colons denote Ruby _symbols_. There's an article with some
explanation here:

http://glu.ttono.us/articles/2005/08/19/understanding-ru...

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


Mage

1/23/2006 7:10:00 PM

0

Mark Volkmann wrote:

>
>There was a long discussion about what symbols are recently, so I
>hesitate to try to simplify this, but here goes. Think of a symbol as
>a string that will be the same object in memory each time you use it.
>For example, "foo" and "foo" will be two different objects in memory,
>but :foo and :foo will refer to the same object.
>
>
I think I understand now, thanx.

>
>
>
>>The benefits I can see are variable length arguments, and the arguments
>>placed don't have to be in the same order. Coming from java, I'm
>>actually a little wary about this, but I sort of understand the
>>usefulness, especially after reading the Rails book.
>>
>>
>
>I don't think it's common in Ruby to use Hashes for this purpose.
>Usually methods have fixed parameters and you don't pass them in a
>Hash.
>
>
Actually, database connection parameters are good example for variable
length arguments. Sometimes you want to skip the port number and the
authentication data, other times you want only defne the user and the
database name.

Mage




Zach

1/23/2006 7:20:00 PM

0

Exactly. I see Rails using this especially in generating views from ERB.
"Almost" every parameter can be omitted depending on how you want to
generate the view. (I'm mainly talking about the helper tags).

-Zach

Mage wrote:

> Mark Volkmann wrote:
>
>>
>> There was a long discussion about what symbols are recently, so I
>> hesitate to try to simplify this, but here goes. Think of a symbol as
>> a string that will be the same object in memory each time you use it.
>> For example, "foo" and "foo" will be two different objects in memory,
>> but :foo and :foo will refer to the same object.
>>
>>
> I think I understand now, thanx.
>
>>
>>
>>
>>> The benefits I can see are variable length arguments, and the arguments
>>> placed don't have to be in the same order. Coming from java, I'm
>>> actually a little wary about this, but I sort of understand the
>>> usefulness, especially after reading the Rails book.
>>>
>>
>>
>> I don't think it's common in Ruby to use Hashes for this purpose.
>> Usually methods have fixed parameters and you don't pass them in a
>> Hash.
>>
>>
> Actually, database connection parameters are good example for variable
> length arguments. Sometimes you want to skip the port number and the
> authentication data, other times you want only defne the user and the
> database name.
>
> Mage
>
>
>
>


Zach

1/23/2006 7:31:00 PM

0

"The fact that the right-hand side is surrounded by curly braces is
what makes it a Hash. Each key/value pair initially added to the Hash
looks like "key => value"."

I don't know about the braces, but I was meaning more about the
Parenthesis (sorry about the type in the earlier example) for example:
|
link_to("View Article", :controller => "blah", :action => "yay", :id => 1)|

I guess I'm clueless as to what the difference is now between sending it
a block and sending it parameterized symbols?

-Zach

Mark Volkmann wrote:

>On 1/23/06, Zach <zacharooni@comcast.net> wrote:
>
>
>>I may be totally off base, being a Ruby Newbie myself, but I believe the
>>point of the :variable is sort of passing a HashMap to the method...for
>>instance:
>>
>>inside the method
>> center = { :x => 1, :y => 2 }
>>
>>
>
>The fact that the right-hand side is surrounded by curly braces is
>what makes it a Hash. Each key/value pair initially added to the Hash
>looks like "key => value". In this particular case, they decided to
>use symbols for keys which is pretty common. The colon means that the
>word following it is a symbol. They could have also used String keys.
>
>There was a long discussion about what symbols are recently, so I
>hesitate to try to simplify this, but here goes. Think of a symbol as
>a string that will be the same object in memory each time you use it.
>For example, "foo" and "foo" will be two different objects in memory,
>but :foo and :foo will refer to the same object.
>
>
>
>>you can refer to the parameters as :x and :y.
>>
>>
>
>Well, in a Hash they are called keys.
>
>
>
>>As opposed to mandating
>>the prototype of the method being center(x, y).
>>
>>
>
>That's a good point. Passing a Hash to a method, in a way, allows you
>to pass arbitrary parameters if you think of the keys as being
>parameter names the values as being parameter values.
>
>
>
>>The benefits I can see are variable length arguments, and the arguments
>>placed don't have to be in the same order. Coming from java, I'm
>>actually a little wary about this, but I sort of understand the
>>usefulness, especially after reading the Rails book.
>>
>>
>
>I don't think it's common in Ruby to use Hashes for this purpose.
>Usually methods have fixed parameters and you don't pass them in a
>Hash.
>
>
>
>>Mage wrote:
>>
>>
>>
>>>Joe Van Dyk wrote:
>>>
>>>
>>>
>>>>On 1/23/06, Mage <mage@mage.hu> wrote:
>>>>
>>>>
>>>>
>>>>The second edition of the book was released two years ago or so and
>>>>covers Ruby 1.8. You should read that one instead.
>>>>
>>>>Here's a pretty good summary of the changes in Ruby 1.8.
>>>>http://whytheluckystiff.net/articles/rubyOneEi...
>>>>
>>>>
>>>>
>>>>
>>>Thanx.
>>>
>>>One of the things I don't understand are the semicolons. When I read
>>>the Book, it said:
>>>
>>>class SomeThing
>>> atrr_reader :x, :y
>>>end
>>>
>>>I figured out that the attr_reader need to get the name of the
>>>instance variables.
>>>
>>>However, what is this code good for?
>>>
>>>def make_point_hash( point )
>>> center = { :x => 1, :y => 2 }
>>> big = { :r => 10 }
>>> center.merge( big ).merge( point ) end
>>>make_point_hash( { :x => 20 } )
>>>
>>>#=> {:y=>2, :r=>10, :x=>20}
>>>
>>>What is that those semicolons do?
>>>
>>> Mage
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>
>>
>
>
>--
>R. Mark Volkmann
>Partner, Object Computing, Inc.
>
>
>
>