Where is the extar end keyword.


W

William Colls

ruby 1.9.1p378 (2010-01-10 revision 26273) [x86_64-linux]
Kubuntu 10.04 64 Bit.

I know this is REALLY basic stuff, but has me stumped. The following is
an example from the Pick Axe book (Seventh printing Dec 2005):

require 'tk'
class PigBox
def pig(word)
leading_cap = word =~ /^[A-Z]/
word.downcase!
res = case word
when /^[aeiouy]/
word+"way"
when /^([aeiouy]+)(.*)/
$2+$1+"ay"
else
word
end # else condition of case
leading_cap ? res.capitalize : res
end. # method pig

def show_pig
@text.value = @text.value.split.collect{ |w| pig(w)
}.join(" ")
end # method show_pig

def initialize
ph = { 'padx' => 10, 'pady' => 10 } # Common Options

root = TkRoot.new { title "Pig" }
top = TkFrame.new(root) { background "white" }

TkLabel.new(top) { text 'Enter Text:' ; pack(ph) }

@text = TkVariable.new
TkEntry.new(top, 'textvariable' => @text).pack(ph)

pig_b = TkButton.new(top) { text 'Pig It' ; pack ph }
pig_b.command { show_pig }
exit_b = TkButton.new(top) {text 'Exit'; pack ph}
exit_b.command { exit }
top.pack('fill' =>'both', 'side' =>'top' )
end # method initialize
end # Class PigBox

PigBox.new
Tk.mainloop

When I run it, I get an error as follows:

Ex2.rb:38: syntax error, unexpected keyword_end, expecting $end
end # Class PigBox

I Understand that the error message is telling me that I have an extra
end keyword. The interpretor expected the end of File. But I can't
determine which is extra "end". Comparing line by line with text in the
book, it appears identical. Downloading the source from the web site,
and it runs as expected, and again, line by line comparison seems to be
identical.

So what have I miss-typed?

Thanks for your time.
 
Ad

Advertisements

R

R. Saksida

[Note: parts of this message were removed to make it a legal post.]
end. # method pig

There's an extra dot after the 'end'.


ruby 1.9.1p378 (2010-01-10 revision 26273) [x86_64-linux]
Kubuntu 10.04 64 Bit.

I know this is REALLY basic stuff, but has me stumped. The following is
an example from the Pick Axe book (Seventh printing Dec 2005):

require 'tk'
class PigBox
def pig(word)
leading_cap = word =~ /^[A-Z]/
word.downcase!
res = case word
when /^[aeiouy]/
word+"way"
when /^([aeiouy]+)(.*)/
$2+$1+"ay"
else
word
end # else condition of case
leading_cap ? res.capitalize : res
end. # method pig

def show_pig
@text.value = @text.value.split.collect{ |w| pig(w)
}.join(" ")
end # method show_pig

def initialize
ph = { 'padx' => 10, 'pady' => 10 } # Common Options

root = TkRoot.new { title "Pig" }
top = TkFrame.new(root) { background "white" }

TkLabel.new(top) { text 'Enter Text:' ; pack(ph) }

@text = TkVariable.new
TkEntry.new(top, 'textvariable' => @text).pack(ph)

pig_b = TkButton.new(top) { text 'Pig It' ; pack ph }
pig_b.command { show_pig }
exit_b = TkButton.new(top) {text 'Exit'; pack ph}
exit_b.command { exit }
top.pack('fill' =>'both', 'side' =>'top' )
end # method initialize
end # Class PigBox

PigBox.new
Tk.mainloop

When I run it, I get an error as follows:

Ex2.rb:38: syntax error, unexpected keyword_end, expecting $end
end # Class PigBox

I Understand that the error message is telling me that I have an extra
end keyword. The interpretor expected the end of File. But I can't
determine which is extra "end". Comparing line by line with text in the
book, it appears identical. Downloading the source from the web site,
and it runs as expected, and again, line by line comparison seems to be
identical.

So what have I miss-typed?

Thanks for your time.
 
Ad

Advertisements

M

Mike Cargal

You would't happen to be a COBOL programmer would you? no insult =
intended, but appears that your problem is a period after the 'end' for =
the pig method.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top