Okay, I KNOW I'm just doing something dumb here, but I just cannot get this to work.
I have an opportunity object
class Opportunity
attr_accessor :effort
attr_accessor :value
def initialize(effort,value)
# set values to 1 + the Rayleigh distribution (rounded)
@effort = 1 + (effort * Math.sqrt(0-2*Math.log(1-rand()))).round
@value = 1 + (value * Math.sqrt(0-2*Math.log(1-rand()))).round
end
end
I push a set of these onto an array (that's a property of another object) and then I want to sort those by specific properties (like effort)
# Order the working backlog
# (see https://ruby-doc.org/core-2.4.3/Array.html#method-i-sort_by-21)
puts workingBacklog.backlog[0].effort
workingBacklog.backlog.sort_by! {|opA,opB| opA.effort <=> opB.effort }
Here's sample output...
6
3cmc.rb:57:in `block (2 levels) in <main>': undefined method `effort' for
nil:NilClass (NoMethodError)
from 3cmc.rb:57:in `each'
from 3cmc.rb:57:in `sort_by'
from 3cmc.rb:57:in `sort_by!'
from 3cmc.rb:57:in `block in <main>'
from 3cmc.rb:51:in `each'
from 3cmc.rb:51:in `<main>'
So I KNOW there's an array of non-NULL objects there because that "6" on the first line of output is non-Null. But right after that it looks like the proverbial wheels come off. What the heck is going on here?