This site is a preview of the curriculum for our Summer 2018 bootcamp in Burlington, Vermont. As we continue our preparation, courses and lessons will appear and disappear; we will rename, rearrange, clarify, and obfuscate as needed... Please consider this a work in progress and keep checking in.

Ruby Objects:
Reopening Classes


Slides

Reopening classes

class Fixnum
  def divisible_by? n
    self % n == 0
  end
end

4.divisible_by? 2 #=> true
4.divisible_by? 3 #=> false

Reopening classes

  • in Ruby, classes can be opened anywhere
  • possible to make additions or changes

    class Student
      def last_name
        @last_name
      end
    end
    
    class Student
      def first_name
        @first_name
      end
    end
    

Monkey Patching

  • Reopening a system or library class is known pejoratively as Monkey Patching
  • Very powerful & dangerous technique

With great monkey power comes great monkey responsibility.

  - Spider Monkey




Comments

comments powered by Disqus