On Thu, May 31, 2012 08:58, Maksym Melnychok wrote: > Does anyone else finds attribute query methods semantically confusing? > > Hi, > > Consider this code: > > post = Post.new(:visible => true, :url => "http://com") > > if post.visible? > puts "ima visible!" > end > > if post.url? > puts "ima url! (wait wat? o_0)" > end > > Does this feel right to you? In case with post.url? i read it as "Hey > post object, are you an url?" which is apparently not what the code > will do. > > So it seems like semantically perfect flag checks go together with > totally confusing(for a reader) way of checking whether an attribute > is present or not. > > I would generate attribute query methods only for boolean attributes.
I am not sure that I understand your point, but in Ruby anything that is neither nil nor false is true. Thus returning the url string, if not nil, is the same as saying that it is true but also allows access to the actual data without having to send another message. -- *** E-Mail is NOT a SECURE channel *** James B. Byrne mailto:byrn...@harte-lyne.ca Harte & Lyne Limited http://www.harte-lyne.ca 9 Brockley Drive vox: +1 905 561 1241 Hamilton, Ontario fax: +1 905 561 0757 Canada L8E 3C3 -- 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+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.