Skip to content

Instantly share code, notes, and snippets.

@Dishwasha
Created July 29, 2013 18:26
Show Gist options
  • Save Dishwasha/6106462 to your computer and use it in GitHub Desktop.
Save Dishwasha/6106462 to your computer and use it in GitHub Desktop.
module namespacing
module A
def hello
puts "hello"
end
end
module A
module B
include A
end
end
obj = Object.new
obj.extend A::B
obj.hello
@AndrewO
Copy link

AndrewO commented Jul 29, 2013

Please, no one ever use this.

module A
 def hello
   puts "is an A::B" if self.kind_of?(A::B)
   puts "module state preserved" if @foo
   puts "hello"
 end
end

module A
  module B
    include A
    def hello
      @foo = true
      super
    end
  end
end

obj = Object.new
obj.extend A::B

obj2 = Object.new
obj2.extend A

obj.hello
obj2.hello

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment