Skip to content

Instantly share code, notes, and snippets.

@DanielVartanov
Created March 26, 2011 12:07
Show Gist options
  • Save DanielVartanov/888225 to your computer and use it in GitHub Desktop.
Save DanielVartanov/888225 to your computer and use it in GitHub Desktop.
module Rubinius
class PrependedModule < IncludedModule
attr_reader :module
def initialize(mod, superclass)
@module = mod
@superclass = superclass
super(mod)
end
def inspect
"#<PrependedModule #{@module.to_s}>"
end
end
end
class Module
attr_reader :prepended_module # for the sake of simplicity let's take just one for now
def prepend(mod)
@prepended_module = Rubinius::PrependedModule.new(mod, self)
end
def direct_superclass
if @superclass && @superclass.prepended_module && @superclass.prepended_module != self
@superclass.prepended_module
else
@superclass
end
end
end
# -----------------------------------------
class Government
def power
"belongs to government"
end
end
module People
def power
"belogs to people"
end
Government.prepend self
end
puts Government.new.metaclass.superclass_chain.inspect
# => [#<PrependedModule People>, Government, Object, #<IncludedModule Kernel>] <----- looks good, but...
puts Government.new.power
# => belongs to government <---- ...is this right? ;)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment