Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xenocampanoli/83eff64cf27c1df76a75d7207236616c to your computer and use it in GitHub Desktop.
Save xenocampanoli/83eff64cf27c1df76a75d7207236616c to your computer and use it in GitHub Desktop.
Example of case not working with class
xeno@xeno-Latitude-E7450:~/garage/ex15$ ruby try3.rb
trace Array
NOPE
trace String
NOPE
trace MyThingy
NOPE
trace Hash
NOPE
xeno@xeno-Latitude-E7450:~/garage/ex15$ cat try3.rb
class MyThingy
end
def caseyMeth(someArg)
puts "trace #{someArg.class}"
case someArg.class
when Array
puts "Array"
when String
puts "String"
when MyThingy
puts "MyThingy"
else
puts "NOPE"
end
end
caseyMeth(Array.new)
caseyMeth("Some string")
caseyMeth(MyThingy.new)
caseyMeth(Hash.new)
xeno@xeno-Latitude-E7450:~/garage/ex15$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment