Skip to content

Instantly share code, notes, and snippets.

@speed-of-light
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save speed-of-light/8950089 to your computer and use it in GitHub Desktop.

Select an option

Save speed-of-light/8950089 to your computer and use it in GitHub Desktop.
Ruby Idioms
module Foo
def self.included base
base.send :include, InstanceMethods
base.extend ClassMethods
end
module InstanceMethods
def bar1
'bar1'
end
end
module ClassMethods
def bar2
'bar2'
end
end
end
class Test
include Foo
end
Test.new.bar1 # => "bar1"
Test.bar2 # => "bar2"
#from http://stackoverflow.com/questions/10692961/inheriting-class-methods-from-mixins
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment