Created
October 17, 2011 20:53
-
-
Save LTe/1293765 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Object | |
def self.define_method(*args) | |
"fuck it" | |
end | |
end | |
foo = Class.new(ExampleClass) do | |
def bar | |
puts "bar" | |
end | |
def self.name | |
puts "hello" | |
"lolz" | |
end | |
def class_name | |
puts self.class.name | |
end | |
end.freeze | |
puts "Nazwa #{foo.name.inspect}" | |
foo.freeze | |
Foo = foo | |
puts "Nazwa #{foo.name.inspect}" | |
foo = Class.new | |
n = 20 | |
puts "N = #{n}" | |
n.times do |i| | |
eval("Foo#{i} = foo") | |
end | |
puts foo.name.gsub("Foo", '').to_f / n | |
n.times do |i| | |
self.class.send(:remove_const, :"Foo#{i}") | |
end | |
foo.name | |
#puts "Nazwa #{foo.name.inspect}" | |
puts "Nazwa #{foo.name.inspect}" | |
puts "Nazwa #{foo.inspect}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ExampleModule | |
module Deeper | |
module InstanceMethods | |
def my_instance_method | |
end | |
end | |
module ClassMethods | |
def my_class_method | |
end | |
end | |
end | |
def self.included(base) | |
base.send(:include, Deeper::InstanceMethods) | |
base.send(:extend, Deeper::ClassMethods) | |
end | |
end | |
class ExampleClass | |
include ExampleModule | |
AnotherExampleModule = Module.new | |
end | |
ExampleClass.instance_eval do | |
remove_const :AnotherExampleModule if(defined?(ExampleClass::AnotherExampleModule)) | |
if(defined?(ExampleClass::Deeper) && ExampleClass.constants.include?(:Deeper) && ExampleClass::Deeper.is_a?(Module)) | |
remove_const :Deeper | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment