Created
September 14, 2010 06:19
-
-
Save liwh/578627 to your computer and use it in GitHub Desktop.
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 MyModule | |
module ClassMethods | |
def act_as_my_module(params) | |
#Note that in order to avoid having to escape string delimiters, we use a #special, multiline string syntax. Text between <<-DELIM ... DELIM is treated as a #plain old string. In this case, our string is Ruby code intended to be evaluated by #class_eval. | |
class_eval do <<-DELIM | |
def some_method | |
#remember , string substitution | |
#is OK here. e.g., #{params[:foo]} | |
end | |
DELIM | |
end | |
end | |
end | |
module InstanceMethods | |
#generic instance methods go here | |
end | |
def self.included(base) | |
#add class method | |
base.extend ClassMethods | |
#add instance method | |
base.class_eval do | |
include InstanceMethods | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment