Ever need to do !object.nil? - I do and frequently. This patch is basically rolling up an extension i end up adding to every project i work on. Sure using !object.nil? to see if an instance is not nil works but how much more meaningful and elegant is object.not_nil? ? Creating a separate plugin for this small but powerful feature would be crazy so heres the patch to better all the rails projects out there. This patch extends Object and NilClass respectively: "any object".not_nil? #=> true Object.new.not_nil? #=> true Object.not_nil? #=> true nil.not_nil? #=> false Tests included! Please add +1 to the ticket if your inclined to do so... http://dev.rubyonrails.org/ticket/10499 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
matthew deiters wrote:> Ever need to do !object.nil? - I do and frequently. This patch is > basically rolling up an extension i end up adding to every project i > work on.Um... why not just do if object .... Should be the same as !object.nil?, right? Jeff --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 13, 1:23 pm, matthew deiters <MDeit...@gmail.com> wrote:> Ever need to do !object.nil? - I do and frequently. This patch is > basically rolling up an extension i end up adding to every project i > work on. > > Sure using !object.nil? to see if an instance is not nil works but how > much more meaningful and elegant is object.not_nil? ? Creating a > separate plugin for this small but powerful feature would be crazy so > heres the patch to better all the rails projects out there.If readability is the objective here you can just as easily do: "if not object.nil?" or "unless object.nil?" --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Hi -- On Thu, 13 Dec 2007, Jeff wrote:> > matthew deiters wrote: >> Ever need to do !object.nil? - I do and frequently. This patch is >> basically rolling up an extension i end up adding to every project i >> work on. > > Um... why not just do > > if object .... > > Should be the same as !object.nil?, right?Almost. The edge case is when object is false. !false.nil? is true, but the if test will fail. It''s unusual for that case to matter, though it''s not impossible that it could. David -- Training for 2008! Ruby on Rails training by David A. Black/Ruby Power and Light, LLC: * Intro to Rails, New York, NY, February 4-7 2008 * Advancing With Rails, New York, NY, February 11-14 2008 Hosted by Exceed Education. See http://www.rubypal.com for details! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
"if object" works but its a trivial example. in more complex scenarios like: if you_are_happy? && object a&& object.is_feeling_funky? object.do_something end Sure it works...but it loses its meaning. The less mental translation i need to make the better...code should be easy to read. the implicit behavior of "if object" in many contexts is not sufficient. On Dec 13, 3:59 pm, Jeff <cohen.j...@gmail.com> wrote:> matthew deiters wrote: > > Ever need to do !object.nil? - I do and frequently. This patch is > > basically rolling up an extension i end up adding to every project i > > work on. > > Um... why not just do > > if object .... > > Should be the same as !object.nil?, right? > > Jeff--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---