Skip to content

Instantly share code, notes, and snippets.

@liwh
Created September 14, 2010 06:19
Show Gist options
  • Save liwh/578627 to your computer and use it in GitHub Desktop.
Save liwh/578627 to your computer and use it in GitHub Desktop.
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