Sha256: a41fd0e3f4016dcc4dbea3f378a38f54b12f36bda7e3eb69a46f1cd410e8aa21

Contents?: true

Size: 858 Bytes

Versions: 2

Compression:

Stored size: 858 Bytes

Contents

# -*- coding: utf-8 -*-

# Class extensions


class Class

  # Make all the methods public for a block.
  #
  # This is especially useful for unit testing
  # a class's private and protected methods
  #
  # From http://blog.jayfields.com/2007/11/ruby-testing-private-methods.html
  #
  # @example
  #   MyClass.publicize_methods do
  #     ...call some method that was private or protected...
  #   end
  #
  # @return void
 
  def publicize_methods
    saved_private_instance_methods = self.private_instance_methods
    saved_protected_instance_methods = self.protected_instance_methods
    self.class_eval {
      public *saved_private_instance_methods 
      public *saved_protected_instance_methods 
    }
    yield
    self.class_eval {
      private *saved_private_instance_methods
      protected *saved_protected_instance_methods 
    }
  end

end


Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sixarm_ruby_ramp-5.0.1 lib/sixarm_ruby_ramp/class.rb
sixarm_ruby_ramp-5.0.0 lib/sixarm_ruby_ramp/class.rb