Dadeo
江湖少侠
case [a, b, c, d] when x: 'nothing happens' when y: 'nothing happens' when z: 'nothing happens' when a: 'render this option' end
case object when condition 1 do something when condition 2 do something ... end
#!/usr/bin/env ruby # # Created by Yudi Xue on 2007-08-11. # Copyright (c) 2007. All rights reserved. case "I am falling for her" when /fall/ puts "yes, You said fall" else puts "there is no match..." end case /fall/ when "I am falling for her" puts "yes, you said fall" else puts "there is no match..." end
=> case(a)?b == case(b)?a
case [3, 45, 6, 'abc'].inlcude? when 1: 'no good' when 3: 'good!' when 'lolo': 'no good' end irb => not not enough arguments error
a = [1,2,3,4] result = case when a.include?(1): 'this is what i want' when a.include?(11): 'not result' when a.include?(15): 'no good' end
a = [1,2,3,4] b = 2 result = case b when *a: "yes!" else "no!" end
查看个人网站
查看详细资料
TOP
江湖大侠
a = '1' b='1' a===b =>true
a=1 b='1' b===a.to_s =>true a===b.to_i =>true
栏目管理员