Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2013
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Dog
  2.     def speak
  3.         woof
  4.     end
  5. end
  6.  
  7. def woof
  8.     if @dog_generic == nil
  9.         puts "@dog_generic isn't scoped when .woof is called from a class method!\n"
  10.     else
  11.         puts "@dog_generic is scoped when .woof is called from the global scope. See:\n" + @dog_generic
  12.     end
  13. end
  14.  
  15. @dog_generic = "Woof!"
  16. lassie = Dog.new
  17. lassie.speak #=> @dog_generic isn't scoped when .woof is called from a class method!\n
  18.  
  19. woof #=> @dog_generic is scoped when .woof is called from the global scope. See:\nWoof!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement