Praktisches gem von Reg Braithwaite mit dem Methoden-Aufrufe auf nil-Objekten abgefangen werden können.
# Ohne andand:
@user = User.find(1)
@address = @user ? @user.address : nil
# Mit andand:
@address = User.find(1).andand.address
Enthält außerdem noch tap zum leichten debugging:
# Original:
p [1, 2, 3].reverse.map {|x| x**2 }
# Debug durch Auseinanderrupfen und Zwischenvariable:
bla = [1, 2, 3].reverse
p bla
p bla.map {|x| x**2 }
# Debug mit tap:
p [1, 2, 3].reverse.tap {|d| p d }.map {|x| x**2 }
Einfach sudo gem install andand und
require 'rubygems'
require 'andand'
in den Code.
Ähnlich praktisch ist der tee-Befehl auf der Commandline:
ps aux | tee p.txt | more
ps aux gibt alle laufenden Prozesse aus, tee p.txt schreibt die Ausgabe von ps aux in die Datei p.txt und gibt sie weiter an more.
Update:
Rails 2.3 hat andand-ähnliche Funktionalität schon eingebaut: try
@address = User.find(1).try(:address)
Mehr dazu: ozmm.org/posts/try.html
![]()
Parkinson shows how you can go into the board of directors and get approval for building a multi-million or even billion dollar atomic power plant, but if you want to build a bike shed you will be tangled up in endless discussions.
[...]
This is a metaphor indicating that you need not argue about every little feature just because you know enough to do so. Some people have commented that the amount of noise generated by a change is inversely proportional to the complexity of the change.
Passend zur Diskussion über die lustigen neuen Array-Funktionen in Rails 2.2.
Interessantes "Un-Blog" und Code-Repository über Code, vornehmlich Ruby.
Apples Tutorial gibt einen guten Überblick und führt einen durch die Entwicklung eines kleinen Programms.
Each language has its purpose, however humble. Each language expresses the Yin and Yang of software. Each language has its place within the Tao.
But do not program in COBOL if you can avoid it.
Erklärt einen raffinierten und schnellen Algorithmus für sich kräuselndes Wasser.