Request for feature: nested methods should be private on nesting method

Hi ,

would be nice if nested methods are made private for the nesting
method only, eg

def test1
def test2
p “i am test2”
end
test2
end

test1
test2 <== this one should fail; ie only test1 should see test2

maybe to invoke test2 from outside, we may need to do test1::test2

kind regards -botp

Hi,

This doesn’t really make sense. The first part sounds like you request
nested functions (not methods!):

The second part sounds like you want methods to be objects and have
their own methods.

Nested functions can be achieved by using lambdas or procs. For the
second part I’d simply use private methods. Sure, they cannot be
restricted to a certain method. But that should never be a problem.

On Apr 12, 2012, at 9:46 AM, botp wrote:

test1
test2 <== this one should fail; ie only test1 should see test2

maybe to invoke test2 from outside, we may need to do test1::test2

Please file language feature requests here:

so the ruby committers will see them.

As Jan said, this doesn’t really fit the language. Methods have always
belonged to classes or modules, and now you request them to belong to
other methods instead. Lambdas will probably do the job just fine.

Also, it would break old code - for example currently Camping relies
on the way defining a method insde another method works.

– Matma R.