Discussion: Newbie help
Afficher un message
Vieux 16/09/2007, 01h16   #1
Ali Koubeissi
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Newbie

Hey, I've started with Ruby two days ago, and I have some questions.

1- What's the use of Symbols? I've read that symbols are (Symbols are
lightweight strings. Usually, symbols are used in situations where you
need a string but you won’t be printing it to the screen.), however I
cannot understand how to use them, and so I tried to read some examples
and I got this:

kitty_toys =
[:shape => 'sock', :fabric => 'cashmere'] +
[:shape => 'mouse', :fabric => 'calico'] +
[:shape => 'eggroll', :fabric => 'chenille']
kitty_toys.sort_by { |toy| toy[:fabric] }

Why is he using symbols? I just couldn't understand ;(.

2- Why does a block has to be on the same line when passing argument?
Like in the previous example: kitty_toys.sort_by { |toy| toy[:fabric] }.
If I tried to move the block down, it won't work. Also, if someone could
explain how does the argument get passed to the block. I mean, based on
what?

3- How does a Ruby file compile? Like in Java, your code gets compiled
into bytecode, and then delivered to the JVM. Are there any similarities
in Ruby?

I'm currently reading Programming Ruby 2nd Edition, and this website:
http://poignantguide.net/ruby/chapter-1.html . Any recommendations ?

Thanks in advance.
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
 
Page generated in 0,04820 seconds with 9 queries