K
krzysieq Gazeta.pl
[Note: parts of this message were removed to make it a legal post.]
Hi,
I'm new both to this mailing list and to Ruby. Here's an example, question
will come later.
class PrivateMethodTest
private
def privateMethod(the_string)
'haha! ' + the_string
end
public
def publicMethod(the_string)
self.privateMethod(the_string)
end
end
require 'private.rb'
require 'test/unit'
class PrivateMethodTestTest < Test::Unit::TestCase
def test_publicMethod
var = PrivateMethodTest.new()
assert_equal('haha! test', var.publicMethod('test'))
end
end
Now the question: why is it, that when the self. (bolded in the code) is
there, the test fails, whereas if I remove it, the test is successful? This
is the failure message:
1) Error:
test_publicMethod(PrivateMethodTestTest):
NoMethodError: private method `privateMethod' called for
#<PrivateMethodTest:0x2b0876d805a0>
./private.rb:9:in `publicMethod'
private_test.rb:8:in `test_publicMethod'
What am I missing?
Thanks for any help and sorry if this question is silly
Cheers,
Chris
Hi,
I'm new both to this mailing list and to Ruby. Here's an example, question
will come later.
class PrivateMethodTest
private
def privateMethod(the_string)
'haha! ' + the_string
end
public
def publicMethod(the_string)
self.privateMethod(the_string)
end
end
require 'private.rb'
require 'test/unit'
class PrivateMethodTestTest < Test::Unit::TestCase
def test_publicMethod
var = PrivateMethodTest.new()
assert_equal('haha! test', var.publicMethod('test'))
end
end
Now the question: why is it, that when the self. (bolded in the code) is
there, the test fails, whereas if I remove it, the test is successful? This
is the failure message:
1) Error:
test_publicMethod(PrivateMethodTestTest):
NoMethodError: private method `privateMethod' called for
#<PrivateMethodTest:0x2b0876d805a0>
./private.rb:9:in `publicMethod'
private_test.rb:8:in `test_publicMethod'
What am I missing?
Thanks for any help and sorry if this question is silly
Cheers,
Chris