Skip to content

Commit

Permalink
case
Browse files Browse the repository at this point in the history
  • Loading branch information
neves committed Apr 11, 2010
1 parent 47aca0f commit 61f4782
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions algoritmos/ruby/sintaxe/case.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
x = ARGV.first.to_i

case x
when 1 then puts "um"
when 2 then puts "dois"
end

case x
when 1: puts "um"
when 2: puts "dois"
end

case x
when 1; puts "um"
when 2; puts "dois"
end

case x
when 1
puts "um"
when 2
puts "dois"
end

class PAR
def self.===(numero)
numero % 2 == 0
end
end

class IMPAR < PAR
def self.===(numero)
! super
end
end

case x
when PAR
puts "par"
when IMPAR
puts "impar"
end

0 comments on commit 61f4782

Please sign in to comment.