Created
February 24, 2015 07:30
-
-
Save psahni/087a4cda717db2485d0e to your computer and use it in GitHub Desktop.
ruby 2.0
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 Kernel | |
def from(mod, include: []) | |
raise TypeError, "argument must be a module" unless Module === mod | |
# print include | |
include.each do |name, original| | |
define_method(name, mod.instance_method(original || name)) | |
end | |
end | |
def kernal_test | |
"Hey this test" | |
end | |
end | |
module Bar | |
def bar | |
"bar" | |
end | |
def baz | |
"baz" | |
end | |
end | |
class Foo | |
from Bar, include: {:qux => :bar} | |
end | |
f = Foo.new | |
p f.qux #=> "bar | |
p f.respond_to?(:baz) #=> false | |
p f.kernal_test #So kernal method can be called from both object and the class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment