ako predefinovat triedu atributu objektu
Peter Kruty
xkruty na informatics.muni.cz
Středa Srpen 25 16:47:36 CEST 2004
Zdravim,
mam nasledujuci kod:
class A
attr_accessor :pole
class << @pole
def each_positive
self.each do |item|
if item > 0 then
yield item
end
end
end
end
end
a = A.new
a.pole = [1, -3, 3, -5, 0, 0]
a.pole.each_positive do |i|
puts i
end
Zaujimalo by ma preco toto nefunguje. Kde mam chybu, resp. co robim zle.
Pravdepodobne som nieco zle pochopil. Akt o teda ide ako pridat do triedy
atributu "pole" nejaky iterator (alebo obecne metodu ci atribut), ale iba do
triedy tejto konkretnej instancie, cize akoby pridat to ibe tejto instacii.
Samozrejme to mozem obist vytvorenim podtriedy, ale zaujimalo by ma ci to
naznacenym sposobom.
regards,
-- Peter Kruty, oozy
--
Fingerprint = E893 658B 141D 0998 4976 EF14 905C 90D4 7B22 F749
#!/bin/bash -- require: bash gcc perl guile
perl -we "\$_ =\`guile -c '(display (list->string (reverse (\
string->list \\\"\$ARGV[0]\\\"))))'\`;sub{print}->(s/zoo/alh\
\n/i)" `echo "char a[]=\"Oozy\\n\";int main(){char*i;for(i=a\
;*i!=0;i++)putchar(0[i]);}"|cc -x c - -o $$&&./$$&&rm -f $$`;
"That that is is not not that that is not is not." Jacques Derrida
Další informace o konferenci Ruby