Please explain me this code!! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Please explain me this code!!

name = 'Fisher' case name when /fish/i then puts "Something is fishy here" when 'Smith' then puts "Your name is Smith" end #=> Something is fishy here i don't understand when /fish/i then puts "Something is fishy here" Thanks

1st Mar 2017, 12:57 PM
wally22
2 Answers
+ 11
When you do: case name The program inspects the string stored in variable name to find if: /fish/i In the sense that the string contains a sequence of characters which form the string "fish". If it does, then: puts "Something is fishy here" Hence the program outputs the result.
1st Mar 2017, 1:02 PM
Hatsy Rei
Hatsy Rei - avatar
+ 2
thanks i got it !! /fish/i it s call regular expression?
1st Mar 2017, 8:10 PM
wally22