Recent Changes - Search:

CIS 700

Ajax

Ruby

Rails

Second Life

Navigation


Penn PmWiki

pmwiki.org


edit SideBar

Gotchas

elsif clause ignored

x = 2
if x == 1
  puts 'one'
elseif x == 2
  puts 'two'
else
  puts 'many'
end
Output:
many

Explanation:
Because elsif is misspelled, it looks like an ordinary method call. Syntax coloring helped me find this error, because elseif wasn't the same color as the if and else keywords.

Illegal forward reference

def one
  two
end

one  # Error here!

def two
  puts "success!"
end

one  # This is ok.
Results:
The call to one in the fifth line results in an error message saying that method two is undefined; but if you comment out that line, the call to one in the last line will print "success!".

Explanation:
In Java, method definition happens at compile time; but in Ruby, def is an executable statement; that is, the method gets defined when you execute the def.
Edit - History - Print - Recent Changes - Search
Page last modified on July 02, 2007, at 10:50 AM