sábado, 27 de enero de 2007

L04-RUBY

Hola de nuevo, aquí les voy a publicar algunas características del uso de la sintaxis en ruby:

1) Creción de un nuevo objeto:
Supongamos que tenemos la siguiente clase:
ruby> class Fruta
ruby| def initialize
ruby| @kind = "manzana"
ruby| @condition = "madura"
ruby| end
ruby| end

ruby> miFruta = Fruta.new
Y listo, tenemos nuestra fruta creada.

2)Manejo de condicionales:
En ruby son sencillos, un ejemplo de condicional es el siguiente:

def fact(n)
if n == 0
1
else
n * fact(n-1)
end
end
También tenemos los clásicos "case":
ruby> i=8
8
ruby> case i
ruby| when 1, 2..5 (cuando se pone 2..5, es el rango entre 2 y 5)
ruby| print "1..5\n"
ruby| when 6..10
ruby| print "6..10\n"
ruby| end
6..10

3)Uso de las estructuras de control repetitivas:
a)While
Aquí esta un pequeño ejemplo de un while:
ruby> i = 0
ruby> print "#{i+=1}\n" while i < 3
1
2
3
b)For, a diferencia de otros lenguajes, los for's se manejan con colecciones, aquí tenemos dos ejemplos:
ruby> for num in (4..6) (El 4..6 es un rango, pero es una coleccion)
ruby| print num, "\n"
ruby| end
4
5
6
4..6

Y este es manejando un array:

ruby> for elm in [100,-9.6,"pickle"]
ruby| print "#{elm}\t(#{elm.type})\n"
ruby| end
100 (Fixnum)
-9.6 (Float)
pickle (String)
[100, -9.6, "pickle"]

4)Arrays. En ruby los arrays pueden almacenar objetos de diferentes tipos, y se declaran de la siguiente manera:

ruby> ary = [1, 2, "3"]
[1, 2, "3"]

Podemos concatenarlos también:

ruby> ary + ["foo", "bar"]
[1, 2, "3", "foo", "bar"]
ruby> ary * 2
[1, 2, "3", 1, 2, "3"]

También podemos usar índices numéricos para accesar a sus elementos:

ruby> ary[0]
1
ruby> ary[0,2]
[1, 2]
ruby> ary[-2]
2
ruby> ary[-2,2]
[2, "3"]
ruby> ary[-2..-1]
[2, "3"]

5) Manejo de cadenas. Las cadenas pueden estar entre comillas dobles (" ") o simples (' '):

ruby> "abc"
"abc"
ruby> 'abc'
"abc"

Las comillas simples y dobles a veces tienen efectos diferentes. Una cadena de comillas dobles
permite la presencia embebida de caracteres de escape precedidos por un backslash y la expresión
de evaluación #{ }. Una cadena de comillas simples no realiza esta evaluación, lo que se ve es
lo que se obtiene. Ejemplos:

ruby> print "a\nb\nc","\n"
a
b
c
nil
ruby> print 'a\nb\nc',"\n"
a\nb\nc
nil
ruby> "\n"
"\n"
ruby> '\n'
"\\n"
ruby> "\001"
"\001"
ruby> '\001'
"\\001"
ruby> "abcd #{5*3} efg"
"abcd 15 efg"
ruby> var = " abc "
" abc "
ruby> "1234#{var}5678"
"1234 abc 5678"

El manejo de las cadenas en Ruby es más inteligente e intuitivo que en C. Por ejemplo,
se pueden concatenar cadenas con + y se puede repetir una cadena varias veces con *:

ruby> "foo" + "bar"
"foobar"
ruby> "foo" * 2
"foofoo"

6) Como se llama a un método en Ruby.
En ruby para llamar a un método, simplemente pones el objeto un punto (.) y el nombre del método, por ejemplo:

ruby> "abcdef".length
6

Nota: La evaluación #{}, nos trae el valor de la variable.

Todo lo anterior lo pueden encontrar en la siguiente página, y muchas otras cosas más:
http://es.tldp.org/Manuales-LuCAS/doc-guia-usuario-ruby/doc-guia-usuario-ruby-html/

13 comentarios:

Anónimo dijo...

I am able to make link exchange with HIGH pr pages on related keywords like [url=http://www.usainstantpayday.com]bad credit loans[/url] and other financial keywords.
My web page is www.usainstantpayday.com

If your page is important contact me.
please only good pages, wih PR>2 and related to financial keywords
Thanks
AccicsTus

Anónimo dijo...

Hey everyone, I just signed up on this amazing community forum and desired to say what's up! Have a amazing day!

Anónimo dijo...

leila megan fox, [url=http://discuss.tigweb.org/thread/187756]megan fox maxim magazine[/url] did megan fox have plastic surgery
kim kardasian naked, [url=http://discuss.tigweb.org/thread/187768]kim kardashian topless pics[/url] kim kardashian weight
taylor swift on justin bieber, [url=http://discuss.tigweb.org/thread/187772]taylor swift naked[/url] taylor swift in grease
lyrics for hannah montana songs, [url=http://discuss.tigweb.org/thread/187786]hannah montana life[/url] hannah montanas phone number
how many harry potter books are there, [url=http://discuss.tigweb.org/thread/187792]harry potter half blood dvd fab[/url] harry potter and the deathly hallows part one trailer
what it is like to work on carnival cruise ship, [url=http://discuss.tigweb.org/thread/187798]oprah winfrey and tom cruise[/url] golf cruises to the eastern caribbean
justin bieber one less lonely girl french, [url=http://discuss.tigweb.org/thread/187812]does justin bieber have a dad[/url] justin bieber rare photos him and family
britney spears mime, [url=http://discuss.tigweb.org/thread/187814]britney spears gives blow[/url] dress like britney spears
megan fox next to a school, [url=http://discuss.tigweb.org/thread/175542]megan fox see through[/url] megan fox intimacy

Anónimo dijo...

hi everybody

I just thought it would be good to introduce myself to everyone!

Can't wait to get to know you all better!

-Marshall

Thanks again!

Anónimo dijo...

if you guys unadulterated to appropriate [url=http://www.generic4you.com]viagra[/url] online you can do it at www.generic4you.com, the most trusted viagra drugstore seeking generic drugs.
you can learn drugs like [url=http://www.generic4you.com/Sildenafil_Citrate_Viagra-p2.html]viagra[/url], [url=http://www.generic4you.com/Tadalafil-p1.html]cialis[/url], [url=http://www.generic4you.com/VardenafilLevitra-p3.html]levitra[/url] and more at www.rxpillsmd.net, the primitive [url=http://www.rxpillsmd.net]viagra[/url] roots on the web. well another great [url=http://www.i-buy-viagra.com]viagra[/url] pharmacy you can find at www.i-buy-viagra.com

Anónimo dijo...

Infatuation casinos? verify this new [url=http://www.realcazinoz.com]online casinos[/url] advisor and wing it reduce online casino games like slots, blackjack, roulette, baccarat and more at www.realcazinoz.com .
you can also into our untrained [url=http://freecasinogames2010.webs.com]casino[/url] direct at http://freecasinogames2010.webs.com and overwhelm principal fortune !
another late-model [url=http://www.ttittancasino.com]casino spiele[/url] regard is www.ttittancasino.com , because german gamblers, descend upon during not busy online casino bonus.

Anónimo dijo...

Good day!

It is my first time here. I just wanted to say hi!

Anónimo dijo...

[url=http://www.zdrowie-drnona.pl]dr nona kosmetyki[/url]
http://pl.wikipedia.org/

http://www.zdrowie-drnona.pl/aktualnosci/dr-nona-kuchina

http://www.zdrowie-drnona.pl/regulamin

http://www.zdrowie-drnona.pl/component/virtuemart/category/16/kosmetyki-do-codziennej-higieny

http://www.zdrowie-drnona.pl/component/virtuemart/details/45/16/kosmetyki-do-codziennej-higieny/dezodorant-damski-monel

http://www.zdrowie-drnona.pl/component/virtuemart/details/48/16/kosmetyki-do-codziennej-higieny/p%C5%82yn-do-p%C5%82ukania-jamy-ustnej

http://www.zdrowie-drnona.pl/component/virtuemart/category/17/kosmetyki-do-twarzy
http://www.zdrowie-drnona.pl/component/virtuemart/details/38/15/kosmetyki-do-cia%C5%82a/balsam-solaris

Anónimo dijo...

hardly rot-gut guaranteed to fashion you event vast! Our all cyclical commingle of herbs and aminos is Dr. formulated and proven to arise slackening, practise psychotic unsure and absolute bet your wisecracks!


[url=http://minichill.com]Energy Drink[/url]
[url=http://minichill.com]Energy Drinks[/url]
[url=http://minichill.com]Stress Relief[/url]

[url=http://minichill.com/home/index.html]facebook[/url]
[url=https://www.getreversemortgagehelp.com/]reverse mortgage info[/url]

[url=http://minichill.com/5%20hour%20energy.html]5 Hour Energy[/url]


[url=http://minichill.com/5%20hour%20energy.html]red bull energy[/url]
[url=http://minichill.com/lab/relaxation/index.html]Valerian Root[/url]
[url=http://minichill.com/lab/happiness/index.html]Valerian Root[/url]
[url=http://minichill.com/lab/focus/index.html]L-Theanine[/url]
[url=http://minichill.com/lab/anti-anxiety/index.htmll]GABA[/url]
[url=http://minichill.com/lab/anti-anxiety/index.htmll]Gamma Aminobutyric Acid [/url]


startling Julian with Comestibles and Exceed you can existent a clear life. I impudent in actuality, it's petrifying so take a crop up on and ry it, do it in this time!
Mini Chill? contains a sage commingling of herbs and amino acids called Relarian?, that has been proven, in published clinical trials not just to not unexpectedly contend against accentuate and proclivity, but to in correctness improve your way of thinking willing and maturing noetic accidental on! Mini Polar doesn?t canada entrepreneur drowsiness, so whether you?re in the medial of a stressful hour at flair or enjoying a generalized obscure of age misled with your friends, Mini Chill? is guaranteed to do up your day.



[url=http://minichill.com/ChillRecipes.html]ice cream drinks with alcohol[/url]
[url=http://routeworldbrokers.com/]NY routes[/url]
[url=http://routeworldbrokers.com/]Business appraisals[/url]
[url=http://minichill.com/ChillRecipes.html]eggnog alcohol drink[/url]

[url=http://minichill.com/ChillRecipes.html]cannabis addiction[/url]

[url=http://www.finmedsys.com/]medical billing company[/url]
[url=http://www.finmedsys.com/]medical billing company[/url]
[url=http://www.finmedsys.com/]medical billing company[/url]

[url=http://www.thestatecolumn.com/]state politics[/url]
[url=http://minichill.com/lab/relaxation/index.html]relax magazine[/url]

[url=http://minichill.com/lab/relaxation/index.html]women relax[/url]
[url=http://minichill.com/ChillRecipes.html]alcohol rehabilitation[/url]
[url=http://minichill.com/ChillRecipes.html]alcohol intervention[/url]

Anónimo dijo...

Well, this is my first posting here,,, :--)

Regarding those who are in need of it, in my signature there is some interesting information about [url=http://newmoviereleasesdvd.info/]Watch Movies Online Free[/url].

Anónimo dijo...

top [url=http://www.c-online-casino.co.uk/]www.c-online-casino.co.uk[/url] check the latest [url=http://www.casinolasvegass.com/]las vegas casino[/url] manumitted no consign hand-out at the foremost [url=http://www.baywatchcasino.com/]loosen casino
[/url].

Anónimo dijo...


[url=http://www.squidoo.com/shenenmaoyis][b]sac longchamp[/b][/url]
[url=http://shenenmao.moonfruit.com/#/blog/4572084152][b]sac longchamp[/b][/url]
[url=http://shenenmaoyie.sport.fr/2013/01/03/lv-replique-a-main/][b]sac longchamp[/b][/url]
[url=http://shenenmaoyis.tumblr.com/][b]sac longchamp[/b][/url]
[url=http://www.migente.com/your_page/blog/index.html?profile_id=7795227&profile_name=shenenmaoyii&user_id=7795227&username=shenenmaoyii][b]sac longchamp[/b][/url]

Anónimo dijo...

Having your name connected with UGG boots, involving the well-known as well as not-so-famous makers, produced their [url=http://uggbottesoldes.monwebeden.fr/]bottes ugg[/url] number of wool felt Ugg boots. If or not Bear foot or possibly Emu, those times each and every within the producers have their own method with this vast array. They aren't significantly costly and in reality critically confident meant for foot. Proudly owning described which it mainly relies on the producer. All the Ugg sheepskin boots Suburb Crochet shoe might possibly might be perfectly always be deemed viewed as a totally unique form of Uggs sneaker. It can be even more as being a knit footwear however it's however extremely nice as well similar to a great cold weather start.