From: Brian Candler on 10 Jul 2010 12:08 Kenneth wrote: > Ruby switches expand to the === operator, for example: > > case string > when "" then puts "Empty" > when /^a/ then puts "Starts with a" > end > > is equivalent to: > > if string === "" > puts "Empty" > elsif string === /^a/ > puts "Contains a" > end Actually the arguments are the other way round: if "" === string puts "Empty" elsif /^a/ === string puts "Starts with a" end Another example: case arg when String; puts "it's a string" when Numeric; puts "it's a number" end The first expands to String === arg, which is functionally equivalent to arg.is_a?(String) -- Posted via http://www.ruby-forum.com/.
From: John Crichton on 12 Jul 2010 14:17 Thank you all for your replies/answers. I appreciate the help and explanations. -- Posted via http://www.ruby-forum.com/.
First
|
Prev
|
Pages: 1 2 Prev: [ANN] sqlite3-ruby 1.3.1 Released Next: [ANN] Zbatery v0.3.0 - for newer Rainbows! |