Forum: Italian Ruby user group Re: aiuto programmazione OO

Posted by Andrea Dallera (edwin_bolthar)
on 2010-02-06 21:01
(Received via mailing list)
Per quanto riguarda i nomi delle variabili: capisco perfettamente la tua
perplessità, scrivere una formula con una variabile lunga 20 caratteri
non è bello però, fidati, è il male minore. Avere un codice da mantenere
pieno di cose tipo a,b,c,r1,sf etc è un inferno.
Se proprio non vuoi rinunciare alla brevità nelle formule c'è l'opzione
alias. Esempio:

class MyClass

  def sembra_talco_ma_non_e
    p "kolokolo pollon!"
  end

  alias :st :sembra_talco_ma_non_e

end

test = MyClass.new
test.sembra_talco_ma_non_e
test.st

#output
#"kolokolo pollon!"
#"kolokolo pollon!"

Non te lo consiglio perchè di fatto vai a duplicare metodi.



--
Andrea Dallera
http://usingimho.wordpress.com
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.