[ABE.pm] Seeking comments re OOP (Continuing my series of dumb questions)

Ricardo SIGNES rjbs-perl-abe at lists.manxome.org
Thu Dec 30 09:40:21 CST 2004


* Randy Kramer <rhkramer at gmail.com> [2004-12-30T10:13:49]
> On Wed, 29 Dec 2004 17:07:09 -0500, Ricardo SIGNES wrote:
> > Why?  It would just make things confusing.  You'd have to remember what
> > was an object and what wasn't.  
> 
> Probably a good point.  (I only say probably, because at this point of
> my Ruby learning, it seems intuitive that an object is an object, and
> a member (method, attribute, whatever) of an object would not be an
> object.)  (Clearly, confusion is not a good thiing!)

Just remember, in Ruby: everything is an object.  (This is not exactly
true, but it's close enough for this stage in your use of it.)

> > Because BankBalance isa Number, the cmp method is implemented, and you
> > can sort accounts by blanace.  
> 
> Just out of curiosity, I guess the syntax for that would be something like:
> 
> <bank account>.<bank balance>.sort

AccountLedger.accounts.sort { |a,b| a.balance <=> b.balance }.each { |act|
  puts act.name
}

^^ List all accounts in order of balance.  I think Ruby 1.8's sort_by
can be used, here, though I'm not very intimate with it.

AccountLedger.accounts.sort_by { |a| a.balance }.each { |act|

should be able to replace the above first line.

-- 
rjbs
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.pm.org/pipermail/abe-pm/attachments/20041230/aab1fe4e/attachment.bin


More information about the ABE-pm mailing list