Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Ruby
- attr_accessor :work
- def initialize
- self
- end
- def method
- @work = "I work"
- puts @work
- end
- end
- r = Ruby.new.method
- puts "#{r.work} too"
- # Top doesn't work
- # ============== VS ============== #
- # Bottom works
- class Ruby
- attr_accessor :work
- def initialize
- self
- end
- def method
- @work = "I work"
- puts @work
- end
- end
- r = Ruby.new
- r.method
- puts "#{r.work} too"
- # => 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