<html><head><style>body{font-family:Helvetica,Arial;font-size:13px}</style></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div> <br> <div id="bloop_sign_1436962567632108032" class="bloop_sign"></div> <br><p class="airmail_on" style="color:#000;">On 15 July 2015 at 13:03:21, Duncan Stuart (<a href="mailto:dgmstuart@gmail.com">dgmstuart@gmail.com</a>) wrote:</p> <blockquote type="cite" class="clean_bq"><span><div><div></div><div>
<title></title>
<div dir="ltr"><div><p class=""><span class="">$ </span><span class="">NoExpectedDate</span><span class="">.new ></span>
<span class="">Date</span><span class="">.today<br></span><span class="">=></span> <span class="">true</span></p>
<p class=""><span class="">$ </span><span class="">Date</span><span class="">.today ></span> <span class="">NoExpectedDate</span><span class="">.new<br></span>ArgumentError: comparison of Date with
NoExpectedDate failed<br>
<br>
I think this is because Date's <=> method expects it's
argument to be a Date object or a number ("a numeric value as an
astronomical Julian day number"). I've tried defining to_i and to_r
on NoExpectedDate, but no dice.<br>
<br>
Can I get NoExpectedDate to pretend to be a Date (like
SimpleDelegator lies about it's class)? Is that evil?<br>
<br></p></div></div></div></div></span></blockquote><div><br></div><div>I think this is what coercion is for (e.g. <a href="http://www.mutuallyhuman.com/blog/2011/01/25/class-coercion-in-ruby/">http://www.mutuallyhuman.com/blog/2011/01/25/class-coercion-in-ruby/</a> )</div><div><br></div><div><br></div><div>Fred</div><br><blockquote type="cite" class="clean_bq"><span><div><div><div dir="ltr"><div><p class="">
I suppose I could always just define a method on Event to do this
particular sort, but that seems nasty for all sorts of
reasons:<br>
<br></p>
<p class="">def sort_by_expected_date sort do |a, b| </p>
<p class=""> if b.class = NoExpectedDate </p>
<p class=""> 1</p>
<p class=""> else</p>
<p class=""> a <=> b</p>
<p class=""> end</p>
<p class=""> end</p>
<p class="">end</p>
<p class=""><br></p>
</div>
</div>
_______________________________________________
<br>Chat mailing list
<br>Chat@lists.lrug.org
<br>Archives: http://lists.lrug.org/pipermail/chat-lrug.org
<br>Manage your subscription: http://lists.lrug.org/options.cgi/chat-lrug.org
<br>List info: http://lists.lrug.org/listinfo.cgi/chat-lrug.org
<br></div></div></span></blockquote></body></html>