Issue #5781 has been updated by trans (Thomas Sawyer).


=begin
FYI,

  file, line = *caller[0].split(':')[0..1]
  module_eval %{...}, file, line.to_i

Actually this does work. My problem with #source_location stemmed from getting it from the (({attr_writer})) defined method. What I had to do was:

  def attr_switch(name)
    file, line = *caller[0].split(':')[0..1]
    module_eval %{
      def #{name}=(x)
        @#{name}=x
      end
      def #{name}?
        @#{name}
      end
    }, file, line.to_i
  end

In any case, still would be better to have `attr_accessor :x?` work.
=end

----------------------------------------
Feature #5781: Query attributes (attribute methods ending in `?` mark)
https://bugs.ruby-lang.org/issues/5781#change-35042

Author: trans (Thomas Sawyer)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: 
Target version: next minor


Pretty sure this has come up before, but I'd like to revisit b/c I don't understand why it isn't allowed.

Sometimes I define "query" attributes, and in those cases I'd like the reader method to end in a `?` mark. Currently I have to do:

    # @attribute
    def foo?
      @foo
    end

or, if I don't mind a shadowing bare method,

    attr :foo
    alias_method :foo?, :foo

So why not just allow:

    attr :foo?

Currently this causes an error. But why? It just seems like a waste of potentially cleaner code.


-- 
http://bugs.ruby-lang.org/