From: 7stud -- Date: 2011-05-12T04:28:52+09:00 Subject: Re: Scope problem (?) in implementing Design Patterns in Ruby RichardOnRails wrote in post #998059: > 1) Your case statement syntax doesn't work in ruby 1.9.2: prog.rb:4: syntax error, unexpected ':', expecting keyword_then or ',' or ';' or '\n' You have to use 'then' in place of a colon. 2) Next, I get this error: prog.rb:67:in `evaluate': uninitialized constant Not::All (NameError) from prog.rb:74:in `
' which relates to this code: class Not < Expression def initialize(expression) @expression = expression end def evaluate(dir) all = All.new.evaluate(dir) other = @expression.evaluate(dir) all - other end end In ruby, constants are looked up like directories and files. When you are inside the Not class (which is a module), the 'directory' you are in for constant lookups is the 'Not' directory. When you write All.new, because the name All is not preceded by a directory name, ruby looks in the current 'directory' for the constant All. The current directory is Not, so ruby is looking for Not::All, i.e. the 'file' All in the 'directory' Not. However, All is not defined inside Not, so you get an error. In fact, there is not constant named All defined anywhere in your program. -- Posted via http://www.ruby-forum.com/.