From: sto.mar@... Date: 2013-02-05T22:58:55+09:00 Subject: Re: old syntax? what's going on here Am 05.02.2013 14:33, schrieb tamouse mailing lists: > I have this in a _spec.rb file: (a gem I inherited at work) > > Open3.expects(:popen3).with do |command| > case part_of_command > when Regexp: command =~ part_of_command > when String: command.include?(part_of_command) > else raise "Can't match that" > end > end > > which ruby is complaining about: > > spec/ruby_gpg_spec.rb:7: syntax error, unexpected ':', expecting > keyword_then or ',' or ';' or '\n' > when Regexp: command =~ part_of_command > ^ > spec/ruby_gpg_spec.rb:8: syntax error, unexpected keyword_when, > expecting keyword_end > when String: command.include?(part_of_command) > ^ > spec/ruby_gpg_spec.rb:9: syntax error, unexpected keyword_else, > expecting keyword_end > else raise "Can't match that" > ^ > spec/ruby_gpg_spec.rb:241: syntax error, unexpected keyword_end, expecting $end > > I'm completely unfamiliar with what is supposed to be happening above, > but I rather assume that Regexp: and String: have something to do with > the Open3.expects bit. No. This case statement (with corrected syntax of course) uses the class of the object referenced by the `command` variable to branch execution. command = 'list' case command when String puts 'a String' when Regexp puts 'a Regexp' else puts 'neither String nor Regexp' end => a String --