Why is '?' OK in a method name and not OK in a variable name ? 
Author Message
 Why is '?' OK in a method name and not OK in a variable name ?


Sorry if this is a beginner question. Following the Principle Of Least
Surprise (POLS?) I tried to write:

class CacheEntry
   attr_reader :dirty?
   def initialize()

   xxxx other stuff

I expected to be able to then write
   if some_cache_entry.dirty? then xxxx

But that does not work, because apparently '?' cannot be included in a
variable's name.

As a result I ended up writing

class CacheEntry
   def initialize()

   def dirty?


Is there a better way ?



Web:   http://www.*-*-*.com/
Phone: +33 (0) 4 92 27 74 17

Do You Yahoo!?

Sat, 11 Sep 2004 22:48:44 GMT  
 Why is '?' OK in a method name and not OK in a variable name ?

J> class CacheEntry
J>    def initialize()

J>    end
J>    def dirty?

J>    end
J> end

 Write it like this, it will be a little faster

   class CacheEntry
      attr_reader :is_dirty
      alias dirty? is_dirty
      def initialize()


Guy Decoux

Sat, 11 Sep 2004 23:10:19 GMT  
 [ 2 post ] 

 Relevant Pages 

1. Buttons: Mac OK, Windows not OK

2. real fear - that's why Danny was FORCED to defend Kathy Kool: fake sock-name of Dukester's [also not it's real name]

3. Finding the current 'method' name

4. NameError: name '_gtk' is not defined

5. Ok, why no methods on strings?

6. tk_chooseDir requires two clicks on OK after entering a non-existent directory name

7. Why?? Append not ok

8. Using a variable name for a variable name??

9. CAN error out--OK(1073094667) and OK(1073094763)

10. what's the calling method name?

11. I'm sorry, name of instance inside its methods

12. name of object inside it's methods?


Powered by phpBB® Forum Software