Guest User

Untitled

a guest
Aug 5th, 2014
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.54 KB | None | 0 0
  1. class Ruby
  2.  
  3.     attr_accessor :work
  4.  
  5.     def initialize
  6.         self
  7.     end
  8.  
  9.     def method
  10.         @work = "I work"
  11.         puts @work
  12.     end
  13. end
  14.  
  15. r = Ruby.new.method
  16. puts "#{r.work} too"
  17.  
  18. # Top doesn't work
  19. # ============== VS ============== #
  20. # Bottom works
  21.  
  22. class Ruby
  23.  
  24.     attr_accessor :work
  25.  
  26.     def initialize
  27.         self
  28.     end
  29.  
  30.     def method
  31.         @work = "I work"
  32.         puts @work
  33.     end
  34. end
  35.  
  36. r = Ruby.new
  37. r.method
  38. puts "#{r.work} too"
  39.  
  40. # => WHY doesn't top don't work and how do I MAKE it work? (So I can go Ruby.new.method and still get my attr_accessor
Advertisement
Add Comment
Please, Sign In to add comment