Advertisement
Guest User

Test.rb

a guest
Mar 27th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.53 KB | None | 0 0
  1. animals = ["dog", "cat", "chicken", "shark"]
  2.  
  3. if 2 + 2 == 5 #obviously this condition will never be true
  4.   # at this point, animal is still undefined
  5.   animal = "frog"
  6.   puts animal
  7. else
  8.   # animal is now defined as nil, rather than
  9.   # being undefined or defined as "frog"
  10.   puts(animals.find { |animal| animal.length == 5})
  11.   # Rubocop will cite me here for shadowing, becuase it considers animal to
  12.   # still be defined.
  13. end
  14.  
  15. # to see only the relevant offense, run the line below in a terminal:
  16. # rubocop Test.rb --only Lint
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement