Good day! I can''t find two tiny features in Rails that are necessary in my mind. I''m sorry if I''m not right. Thanks for attention! 1. Only-Except filter method. Such as in `before_filter`. This feature is used really often. But I found no method for this in ActiveSupport... 2. Is `Object#not_nil?` logical, isn''t it? It will replace (not obj.nil?) ? something_main_and_important : ''no'' to (beautiful) obj.not_nil? ? something_main_and_important : ''no'' Amn''t I right? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/_94RRSbD13gJ. 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.
Not sure what you are talking about on number 1. For number 2 use Object#blank? And Object#present? -- Richard Schneeman http://heroku.com @schneems Sent from the road On Wednesday, August 15, 2012 at 9:13 AM, kuraga wrote:> Good day! > > I can''t find two tiny features in Rails that are necessary in my mind. I''m sorry if I''m not right. Thanks for attention! > > 1. Only-Except filter method. Such as in `before_filter`. This feature is used really often. But I found no method for this in ActiveSupport... > > 2. Is `Object#not_nil?` logical, isn''t it? It will replace > (not obj.nil?) ? something_main_and_important : ''no'' > to (beautiful) > obj.not_nil? ? something_main_and_important : ''no'' > > Amn''t I right? > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. > To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/_94RRSbD13gJ. > 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. > >-- 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.
среда, 15 августа 2012 г., 17:13:05 UTC+4 пользователь kuraga написал:> > Good day! > > I can''t find two tiny features in Rails that are necessary in my mind. I''m > sorry if I''m not right. Thanks for attention! > > 1. Only-Except filter method. Such as in `before_filter`. This feature is > used really often. But I found no method for this in ActiveSupport... > > 2. Is `Object#not_nil?` logical, isn''t it? It will replace > (not obj.nil?) ? something_main_and_important : ''no'' > to (beautiful) > obj.not_nil? ? something_main_and_important : ''no'' > > Amn''t I right? > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/2jetSh-GybEJ. 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.
1. Something like: class Array def filter_by_only_except options self & Array.wrap(options[:only] || self) - Array.wrap(options[:except] || []) end end 2. No, `present?` is `(not blank?)` but not `(not nil?)`... Good example! `blank?` has an opposite method but not `nil?`. Yes? среда, 15 августа 2012 г., 18:43:15 UTC+4 пользователь richard schneeman написал:> > Not sure what you are talking about on number 1. For number 2 use > > Object#blank? > > And > > Object#present? > > -- > Richard Schneeman > http://heroku.com > @schneems > > Sent from the road > > On Wednesday, August 15, 2012 at 9:13 AM, kuraga wrote: > > Good day! > > I can''t find two tiny features in Rails that are necessary in my mind. I''m > sorry if I''m not right. Thanks for attention! > > 1. Only-Except filter method. Such as in `before_filter`. This feature is > used really often. But I found no method for this in ActiveSupport... > > 2. Is `Object#not_nil?` logical, isn''t it? It will replace > (not obj.nil?) ? something_main_and_important : ''no'' > to (beautiful) > obj.not_nil? ? something_main_and_important : ''no'' > > Amn''t I right? > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-core/-/_94RRSbD13gJ. > To post to this group, send email to rubyonra...@googlegroups.com<javascript:> > . > To unsubscribe from this group, send email to > rubyonrails-co...@googlegroups.com <javascript:>. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-core?hl=en. > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/g0AhALP3pcYJ. 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.
Use a 3rd party lib like http://extensions.rubyforge.org/rdoc/index.html. It has non_nil?, not_nil? blank? and present? probably satisfy most rails devs needs. On Wed, Aug 15, 2012 at 1:35 PM, kuraga <kuraga333@mail.ru> wrote:> 1. Something like: > > class Array > def filter_by_only_except options > self & Array.wrap(options[:only] || self) - Array.wrap(options[:except] || []) > end > end > > > 2. No, `present?` is `(not blank?)` but not `(not nil?)`... > > Good example! `blank?` has an opposite method but not `nil?`. Yes? > > среда, 15 августа 2012 г., 18:43:15 UTC+4 пользователь richard schneeman > написал: >> >> Not sure what you are talking about on number 1. For number 2 use >> >> Object#blank? >> >> And >> >> Object#present? >> >> -- >> Richard Schneeman >> http://heroku.com >> @schneems >> >> Sent from the road >> >> On Wednesday, August 15, 2012 at 9:13 AM, kuraga wrote: >> >> Good day! >> >> I can''t find two tiny features in Rails that are necessary in my mind. >> I''m sorry if I''m not right. Thanks for attention! >> >> 1. Only-Except filter method. Such as in `before_filter`. This feature is >> used really often. But I found no method for this in ActiveSupport... >> >> 2. Is `Object#not_nil?` logical, isn''t it? It will replace >> (not obj.nil?) ? something_main_and_important : ''no'' >> to (beautiful) >> obj.not_nil? ? something_main_and_important : ''no'' >> >> Amn''t I right? >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Core" group. >> To view this discussion on the web visit https://groups.google.com/d/** >> msg/rubyonrails-core/-/_**94RRSbD13gJ<https://groups.google.com/d/msg/rubyonrails-core/-/_94RRSbD13gJ> >> . >> To post to this group, send email to rubyonra...@googlegroups.**com. >> To unsubscribe from this group, send email to rubyonrails-co...@** >> googlegroups.com. >> For more options, visit this group at http://groups.google.com/** >> group/rubyonrails-core?hl=en<http://groups.google.com/group/rubyonrails-core?hl=en> >> . >> >> >> -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-core/-/g0AhALP3pcYJ. > > 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. >-- 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.
Sure I can write my own one-line `not_nil?` method :) But is it logical to: 1. have `nil?` 2. have `present?` in opposite to `blank?` 3. don''t have `not_nil?` Or can''t I say about logical here? среда, 15 августа 2012 г., 22:52:08 UTC+4 пользователь Andrew Kaspick написал:> > Use a 3rd party lib like http://extensions.rubyforge.org/rdoc/index.html. > It has non_nil?, not_nil? > > blank? and present? probably satisfy most rails devs needs. > > On Wed, Aug 15, 2012 at 1:35 PM, kuraga <kura...@mail.ru <javascript:>>wrote: > >> 1. Something like: >> >> >> class Array >> def filter_by_only_except options >> self & Array.wrap(options[:only] || self) - Array.wrap(options[:except] || []) >> end >> end >> >> >> 2. No, `present?` is `(not blank?)` but not `(not nil?)`... >> >> Good example! `blank?` has an opposite method but not `nil?`. Yes? >> >> среда, 15 августа 2012 г., 18:43:15 UTC+4 пользователь richard schneeman >> написал: >>> >>> Not sure what you are talking about on number 1. For number 2 use >>> >>> Object#blank? >>> >>> And >>> >>> Object#present? >>> >>> -- >>> Richard Schneeman >>> http://heroku.com >>> @schneems >>> >>> Sent from the road >>> >>> On Wednesday, August 15, 2012 at 9:13 AM, kuraga wrote: >>> >>> Good day! >>> >>> I can''t find two tiny features in Rails that are necessary in my mind. >>> I''m sorry if I''m not right. Thanks for attention! >>> >>> 1. Only-Except filter method. Such as in `before_filter`. This feature >>> is used really often. But I found no method for this in ActiveSupport... >>> >>> 2. Is `Object#not_nil?` logical, isn''t it? It will replace >>> (not obj.nil?) ? something_main_and_important : ''no'' >>> to (beautiful) >>> obj.not_nil? ? something_main_and_important : ''no'' >>> >>> Amn''t I right? >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Ruby on Rails: Core" group. >>> To view this discussion on the web visit https://groups.google.com/d/** >>> msg/rubyonrails-core/-/_**94RRSbD13gJ<https://groups.google.com/d/msg/rubyonrails-core/-/_94RRSbD13gJ> >>> . >>> To post to this group, send email to rubyonra...@googlegroups.**com. >>> To unsubscribe from this group, send email to rubyonrails-co...@** >>> googlegroups.com. >>> For more options, visit this group at http://groups.google.com/** >>> group/rubyonrails-core?hl=en<http://groups.google.com/group/rubyonrails-core?hl=en> >>> . >>> >>> >>> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Core" group. >> To view this discussion on the web visit >> https://groups.google.com/d/msg/rubyonrails-core/-/g0AhALP3pcYJ. >> >> To post to this group, send email to rubyonra...@googlegroups.com<javascript:> >> . >> To unsubscribe from this group, send email to >> rubyonrails-co...@googlegroups.com <javascript:>. >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-core?hl=en. >> > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/_7JhoeJGxWwJ. 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 Wednesday, August 15, 2012 at 12:01 PM, kuraga wrote:> Sure I can write my own one-line `not_nil?` method :) But is it logical to: > have `nil?` > have `present?` in opposite to `blank?` > don''t have `not_nil?` > > Or can''t I say about logical here?The standard Ruby idiom for the inverse of `if object.nil?` is `if object`. Yes, there is an edge case when object == false, but other than that it works great and should be how you write your code. There is no need for another method that just makes code wordier and harder to read. --josh> среда, 15 августа 2012 г., 22:52:08 UTC+4 пользователь Andrew Kaspick написал: > > Use a 3rd party lib like http://extensions.rubyforge.org/rdoc/index.html. It has non_nil?, not_nil? > > > > blank? and present? probably satisfy most rails devs needs. > > > > On Wed, Aug 15, 2012 at 1:35 PM, kuraga <kura...@mail.ru (javascript:)> wrote: > > > 1. Something like: > > > class Array > > > def filter_by_only_except options > > > > > > self & Array.wrap(options[:only] || self) - Array.wrap(options[:except] || []) > > > > > > end > > > > > > end > > > > > > > > > 2. No, `present?` is `(not blank?)` but not `(not nil?)`... > > > > > > Good example! `blank?` has an opposite method but not `nil?`. Yes? > > > > > > среда, 15 августа 2012 г., 18:43:15 UTC+4 пользователь richard schneeman написал: > > > > Not sure what you are talking about on number 1. For number 2 use > > > > > > > > Object#blank? > > > > > > > > And > > > > > > > > Object#present? > > > > > > > > -- > > > > Richard Schneeman > > > > http://heroku.com > > > > @schneems > > > > > > > > Sent from the road > > > > > > > > > > > > On Wednesday, August 15, 2012 at 9:13 AM, kuraga wrote: > > > > > > > > > > > > > Good day! > > > > > > > > > > I can''t find two tiny features in Rails that are necessary in my mind. I''m sorry if I''m not right. Thanks for attention! > > > > > > > > > > 1. Only-Except filter method. Such as in `before_filter`. This feature is used really often. But I found no method for this in ActiveSupport... > > > > > > > > > > 2. Is `Object#not_nil?` logical, isn''t it? It will replace > > > > > (not obj.nil?) ? something_main_and_important : ''no'' > > > > > to (beautiful) > > > > > obj.not_nil? ? something_main_and_important : ''no'' > > > > > > > > > > Amn''t I right? > > > > > > > > > > -- > > > > > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. > > > > > To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/_94RRSbD13gJ. > > > > > > > > > > To post to this group, send email to rubyonra...@googlegroups.com. > > > > > To unsubscribe from this group, send email to rubyonrails-co...@googlegroups.com. > > > > > For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. > > > To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/g0AhALP3pcYJ. > > > > > > To post to this group, send email to rubyonra...@googlegroups.com (javascript:). > > > To unsubscribe from this group, send email to rubyonrails-co...@googlegroups.com (javascript:). > > > For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. > > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. > To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/_7JhoeJGxWwJ. > To post to this group, send email to rubyonrails-core@googlegroups.com (mailto:rubyonrails-core@googlegroups.com). > To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com (mailto:rubyonrails-core+unsubscribe@googlegroups.com). > For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.-- 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.
"How many ruby developers does it does to ask if something is not false?" Although non-standard, I would argue that the most logical way to write that is: unless object.nil? I know it''s a double-negative, but in fact if you think about it it makes perfect sense -- you''re saying you want to do something unless this thing is nil. And while the standard may be to say if object, you still have to take a mental moment when looking at that code to think about truthy and falsy, whereas my proposal above basically means you don''t have to take that split second to consider truthy and falsy and you get around Josh''s edge case too. It seems to me that if what you''re interested in is a thing being not nil, you should write code that expresses that, instead of writing code where the next developer may have to think about the many truthy values of ruby. Obviously, this is a 6-of-one-half-dozen-of-the-other question. On Aug 15, 2012, at 3:06 PM, Josh Susser wrote:> On Wednesday, August 15, 2012 at 12:01 PM, kuraga wrote: >> Sure I can write my own one-line `not_nil?` method :) But is it logical to: >> have `nil?` >> have `present?` in opposite to `blank?` >> don''t have `not_nil?` >> Or can''t I say about logical here? > > The standard Ruby idiom for the inverse of `if object.nil?` is `if object`. Yes, there is an edge case when object == false, but other than that it works great and should be how you write your code. There is no need for another method that just makes code wordier and harder to read. > > --josh > >> среда, 15 августа 2012 г., 22:52:08 UTC+4 пользователь Andrew Kaspick написал: >>> >>> Use a 3rd party lib like http://extensions.rubyforge.org/rdoc/index.html. It has non_nil?, not_nil? >>> >>> blank? and present? probably satisfy most rails devs needs. >>> >>> On Wed, Aug 15, 2012 at 1:35 PM, kuraga <kura...@mail.ru> wrote: >>>> 1. Something like: >>>> >>>> class Array >>>> def filter_by_only_except options >>>> >>>> self & Array.wrap(options[:only] || self) - Array.wrap(options[:except] || []) >>>> >>>> end >>>> >>>> end >>>> >>>> 2. No, `present?` is `(not blank?)` but not `(not nil?)`... >>>> >>>> Good example! `blank?` has an opposite method but not `nil?`. Yes? >>>> >>>> среда, 15 августа 2012 г., 18:43:15 UTC+4 пользователь richard schneeman написал: >>>>> >>>>> Not sure what you are talking about on number 1. For number 2 use >>>>> >>>>> Object#blank? >>>>> >>>>> And >>>>> >>>>> Object#present? >>>>> >>>>> -- >>>>> Richard Schneeman >>>>> http://heroku.com >>>>> @schneems >>>>> >>>>> Sent from the road >>>>> >>>>> On Wednesday, August 15, 2012 at 9:13 AM, kuraga wrote: >>>>> >>>>>> Good day! >>>>>> >>>>>> I can''t find two tiny features in Rails that are necessary in my mind. I''m sorry if I''m not right. Thanks for attention! >>>>>> >>>>>> 1. Only-Except filter method. Such as in `before_filter`. This feature is used really often. But I found no method for this in ActiveSupport... >>>>>> >>>>>> 2. Is `Object#not_nil?` logical, isn''t it? It will replace >>>>>> (not obj.nil?) ? something_main_and_important : ''no'' >>>>>> to (beautiful) >>>>>> obj.not_nil? ? something_main_and_important : ''no'' >>>>>> >>>>>> Amn''t I right? >>>>>> >>>>>> -- >>>>>> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. >>>>>> To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/_94RRSbD13gJ. >>>>>> To post to this group, send email to rubyonra...@googlegroups.com. >>>>>> To unsubscribe from this group, send email to rubyonrails-co...@googlegroups.com. >>>>>> For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. >>>>> >>>> >>>> -- >>>> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. >>>> To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/g0AhALP3pcYJ. >>>> >>>> To post to this group, send email to rubyonra...@googlegroups.com. >>>> To unsubscribe from this group, send email to rubyonrails-co...@googlegroups.com. >>>> For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. >>> >> >> -- >> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. >> To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/_7JhoeJGxWwJ. >> 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. > > > -- > 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.-- 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 15 August 2012 20:23, Jason Fleetwood-Boldt <tech@datatravels.com> wrote:> "How many ruby developers does it does to ask if something is not false?" > > Although non-standard, I would argue that the most logical way to write that > is: > > unless object.nil? > > I know it''s a double-negative, but in fact if you think about it it makes > perfect sense -- you''re saying you want to do something unless this thing is > nil.Another double-negative idiom for truthiness is "!!": !!ob ? something_main_and_important : ''no'' I can''t see much sense in an additional ".non_nil?" method when there''s at least three alternatives already given :-) -- 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.