Issue #6806 has been updated by drbrain (Eric Hodel).

Assignee set to matz (Yukihiro Matsumoto)
Target version set to 3.0

This would break compatibility with much ruby code.
----------------------------------------
Feature #6806: Support functional programming: forbid instance/class variables for ModuleName::method_name, allow for ModuleName.method_name
https://bugs.ruby-lang.org/issues/6806#change-28551

Author: alexeymuranov (Alexey Muranov)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: 3.0


=begin
What would you say about this proposal?  Is there a better alternative?

I suggest to support functional programming in Ruby by making module methods called with (({ModuleName::method_name})) syntax raise an exception if the method uses instance or class variables (instance variables of the singleton class, of course).
If i understand correctly, currently (({ModuleName::method_name})) and (({ModuleName.method_name})) behave identically, so i propose that they be different:

 module M
   module_function
     def f(x)
       x*x
     end
     def g(x)
       @x ||= x
       @x*@x
     end
 end

 M.f(2) # => 4
 M.g(2) # => 4
 M::f(3) # => 9
 M::g(3) # => Error: instance variable `@x` used in a functional call `M::g`

Current behavior:

 M.f(2) # => 4
 M.g(2) # => 4
 M::f(3) # => 9
 M::g(3) # => 4
=end



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