DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Alexey has posted 28 posts at DZone. View Full User Profile

Extract Part Of Class In Ruby Into Separate Class

03.15.2011
| 2446 views |
  • submit to reddit
        When you need to split class into seveal parts...

New file:
  ClassPart = proc do
    <copy here code you want to move out of the main class>
  end

Original class:
  class MainClass
    class_eval &ClassPart
    ...
  end

I used this approach to create a recycled bin: when i find some functionality not very valuable i move it to the 'recycled bin' part of class. i keep it there for a while. then i delete it altogether from code.