[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

methods, methods override classes and scope

Berlin Brown

4/17/2006 6:33:00 PM

I am trying to figure out how scope works with method in methods (or
actually overriding).

For example, below with the:
def parser.startElement(n, data)

I want to pass top-level variables to it, but I am getting an error the
object is nil.

/html_extract.rb:72:in `startElement': undefined method
`meta_description=' for nil:NilClass (NoMet
odError)
from ./ymhtml.rb:1024:in `parse'
from ./html_extract.rb:95:in `html_parse'
from ./html_extract.rb:115:in `fetch_http_document'
from ./html_extract.rb:46:in `connect_http'
from html_extract_main.rb:12:in `html_extract_main'
from html_extract_main.rb:15


class HTMLMetadata

attr_writer :meta_description
attr_writer :meta_keywords

attr_writer :document_size
attr_writer :links

....
....

# Parse and extract
parser = YmHTML::Parser.new
parser.eliminateWhiteSpace = true

@html_data = HTMLMetadata.new()

# Process only links and the meta tag (including keywords)
def parser.startElement(n, data)
case n

when 'meta'

# Extract the meta content including keywords
# and description
if data['name']
type_lower = data['name'].downcase
if type_lower == 'description'
puts data['content'].downcase
@html_data.meta_description = data['content'].downcase
end


--
Berlin Brown
(ramaza3 on freenode)
http://www.newspiritc...
http://www.newspiritc.../newforums
also checkout alpha version of botverse:
http://www.newspiritc...:8086/universe_home
3 Answers

ndh.00008B@gmail.com

4/18/2006 7:39:00 AM

0

' @html_data = HTMLMetadata.new() '
When you do that, you are creating a class attribute, not an instance
attribute. you need to put that line of code into the initialize method
of your class
e.g.



class Person
@name
attr_accessor :name
end

class Test
@p=Person.new #class attribute
@p.name ='bob'

def initialize
@p =Person.new #instance attribute
@p.name ='joe'
end
def Test.p
@p.name
end
end

t=Test.new
def t.x
@p.name
end

puts Test.p #prints out bob
puts t.x #prints out joe

thomas p.

12/29/2009 9:19:00 AM

0


"j-rod" <j-rod@nospam.net> skrev i meddelelsen
news:4B397F7D.6470A89B@nospam.net...
> Logan Sacket wrote:
>>
>> On Mon, 28 Dec 2009 11:24:17 -0200, John Manning
>> <jrobertm@terra.com.br> wrote:
>>
>> >
>> >The Big Zero
>>
>> Obama years, big negative.
>
> We shall see.
>
> So far it ain't so bad, is it?
>
> Much better than the previous eight.
>
> JAM

Pinky Lee would have been better.


j-rod

12/29/2009 5:00:00 PM

0

"thomas p." wrote:
>
> "j-rod" <j-rod@nospam.net> skrev i meddelelsen
> news:4B397F7D.6470A89B@nospam.net...
> > Logan Sacket wrote:
> >>
> >> On Mon, 28 Dec 2009 11:24:17 -0200, John Manning
> >> <jrobertm@terra.com.br> wrote:
> >>
> >> >
> >> >The Big Zero
> >>
> >> Obama years, big negative.
> >
> > We shall see.
> >
> > So far it ain't so bad, is it?
> >
> > Much better than the previous eight.
> >
> > JAM
>
> Pinky Lee would have been better.

Pinky Lee better than GWB? I agree.

http://farm3.static.flickr.com/2117/1660805048_296f...

JAM