D
Daniel Völkerts
Hello there,
perhaps it is a newbies fault, but I can't figure out where to find my
logical failure.
I'd like to build up a Tree for a Document. The result should contain a
string represantion of this document (e.g. HTML file).
I started writing ...
class Tag
def to_s
yield
end
end
Thats easy so I went on ...
class HtmlTag < Tag
def to_s
'<html>'+yield'</html>'
end
end
That looks the way I want it to look like, but if I call the following
Html = HtmlTag.new
# Okay, not valid HTML. Just for testing.
puts Html {'Hello'}
The interpreter returned
tags.rb:27: undefined method `Html' for main:Object (NoMethodError)
I understand this messages as the Mainobject doesn't have such method,
but why doesn't he send a message to Html called 'to_s'?
If I write
Test = String.new('Test')
and execute a
puts Test
He works fine an returned 'Test'.
Please point me to a solution.
TIA.
perhaps it is a newbies fault, but I can't figure out where to find my
logical failure.
I'd like to build up a Tree for a Document. The result should contain a
string represantion of this document (e.g. HTML file).
I started writing ...
class Tag
def to_s
yield
end
end
Thats easy so I went on ...
class HtmlTag < Tag
def to_s
'<html>'+yield'</html>'
end
end
That looks the way I want it to look like, but if I call the following
Html = HtmlTag.new
# Okay, not valid HTML. Just for testing.
puts Html {'Hello'}
The interpreter returned
tags.rb:27: undefined method `Html' for main:Object (NoMethodError)
I understand this messages as the Mainobject doesn't have such method,
but why doesn't he send a message to Html called 'to_s'?
If I write
Test = String.new('Test')
and execute a
puts Test
He works fine an returned 'Test'.
Please point me to a solution.
TIA.