Skip to content

Instantly share code, notes, and snippets.

@psahni
Created February 24, 2015 07:30
Show Gist options
  • Save psahni/087a4cda717db2485d0e to your computer and use it in GitHub Desktop.
Save psahni/087a4cda717db2485d0e to your computer and use it in GitHub Desktop.
ruby 2.0
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