I have also noted that with @breakdown[2] it doesn't work even though
I know I have a "P" in there!

>> @breakdown[2]
=> #<Treatlist:0x2357a1c @items=[
#<Treatlistitem:0x2351b30 @longname="Back Massage", @spend=10.0,
@prodtreat="T", @numsold=1, @unitcost=10.0>,
#<Treatlistitem:0x234f9fc @longname="Hopi Ear Candles", @spend=10.0,
@prodtreat="T", @numsold=1, @unitcost=10.0>,
#<Treatlistitem:0x234cf90 @longname="Eye Brow Shape", @spend=10.0,
@prodtreat="T", @numsold=1, @unitcost=10.0>,
#<Treatlistitem:0x2349db8 @longname="Full Leg Wax DSS", @spend=18.0,
@prodtreat="T", @numsold=2, @unitcost=10.0>,
#<Treatlistitem:0x23476bc @longname="Bridal Make Up", @spend=10.0,
@prodtreat="T", @numsold=1, @unitcost=10.0>,
#<Treatlistitem:0x2342fcc @longname="Collin Face Powder", @spend=10.0,
@prodtreat="P", @numsold=1, @unitcost=10.0>]>

>> @breakdown[2].items.sum{|item| item.spend if item.prodtreat == "P"}

NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.+
        from /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/
active_support/core_ext/enumerable.rb:63:in `sum'
        from (irb):68:in `inject'
        from /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/
active_support/core_ext/enumerable.rb:63:in `each'
        from /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/
active_support/core_ext/enumerable.rb:63:in `inject'
        from /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/
active_support/core_ext/enumerable.rb:63:in `sum'
        from /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/
active_support/core_ext/enumerable.rb:61:in `sum'
        from (irb):68

This is confusing me mightily!

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to