Method Naming Conflicts

 
   

Ruby Way
By Hal Fulton
Slots : 1.0
Table of Contents
 


Method names can coincide with keywords or local/constant variable names. This is usually not a problem because the dot notation makes things clear.

 

 class MyClass  def end   # keyword as method name  puts "The End"  end end obj = MyClass.new obj.end    # The End 

Local variables may be confused with a private method of the same name, since private methods can be called without dot notation or parentheses, so be careful.

 

 def var    # method belongs to Object class by default  "not 5" end puts var   # not 5 var = 5    # local variable puts var   # 5 puts var()   # not 5 

Knowing what Ruby will do is going to take practiceRuby is more complex than Python.


   

 

 



The Ruby Way
The Ruby Way, Second Edition: Solutions and Techniques in Ruby Programming (2nd Edition)
ISBN: 0672328844
EAN: 2147483647
Year: 2000
Pages: 119
Authors: Hal Fulton

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net