T
timr
Why is it that when you call a private method, you cannot use
self.the_priv_method?
Below is an example that works if you take out self before the method,
but fails with it in.
It is odd because using self should just a more explicit statement.
But either way the method is being sent to the same object.
WEIRD!!!!
Please let me know how you gurus wrap your heads around this
(apparent) inconsistency.
Thanks,
Tim
class TestPrivate
def giveValue
@value
end
def callPriv
self.priv #why can't you put the self in front of a private method?
end
private
def priv
@value = 100
end
end
i = TestPrivate.new
p i
i.callPriv
p i.giveValue
# ~> -:6:in `callPriv': private method `priv' called for #<TestPrivate:
0x33e1f4> (NoMethodError)
# ~> from -:18
# >> #<TestPrivate:0x33e1f4>
self.the_priv_method?
Below is an example that works if you take out self before the method,
but fails with it in.
It is odd because using self should just a more explicit statement.
But either way the method is being sent to the same object.
WEIRD!!!!
Please let me know how you gurus wrap your heads around this
(apparent) inconsistency.
Thanks,
Tim
class TestPrivate
def giveValue
@value
end
def callPriv
self.priv #why can't you put the self in front of a private method?
end
private
def priv
@value = 100
end
end
i = TestPrivate.new
p i
i.callPriv
p i.giveValue
# ~> -:6:in `callPriv': private method `priv' called for #<TestPrivate:
0x33e1f4> (NoMethodError)
# ~> from -:18
# >> #<TestPrivate:0x33e1f4>